Javascript Reference - HTML DOM IFrame height Property








The height attribute from iframe element specifies the height of an iframe.

The height property sets or gets the value of the height attribute in an iframe element.

Browser Support

height Yes Yes Yes Yes Yes

Syntax

Return the height property.

var v = iframeObject.height

Set the height property.

iframeObject.height=pixels




Property Values

Value Description
pixels The height in pixels

Return Value

A String type value representing the height of the iframe in pixels.

Example

The following code shows how to get the height of an iframe.


<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="http://example.com" height="200" width="250"></iframe>
<p id="demo"></p>
<!-- ww w. j  av  a2 s  . c  o m-->
<button onclick="myFunction()">test</button>

<script>
function myFunction() {
    var x = document.getElementById("myFrame").height;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the height 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  va  2s .c  om-->
    document.getElementById("myFrame").height = "400";
}
</script>
</body>
</html>

The code above is rendered as follows: