The width
attribute from <iframe> element
specifies the width of an iframe.
The width
property sets or gets the value of the width attribute in an iframe element.
width |
Yes | Yes | Yes | Yes | Yes |
Return the width property.
var v = iframeObject.width
Set the width property.
iframeObject.width=pixels
Value | Description |
---|---|
pixels | The width in pixels |
A String type value representing the width of the iframe in pixels
The following code shows how to change the width of an iframe.
<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="http://example.com" height="200" width="250"></iframe>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!-- w w w . j a v a 2 s . c o m-->
document.getElementById("myFrame").width = "400";
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to get the width of an iframe.
<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="http://example.com" height="200" width="250"></iframe>
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--from w w w .j a v a2 s . co m-->
var x = document.getElementById("myFrame").width;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: