Javascript Reference - Window length Property








The length property returns the number of frames including iframes in the current window.

Browser Support

length Yes Yes Yes Yes Yes

Syntax

window.length

Return Value

The number of frames (including iframes) in the current window.




Example

The following code shows how to Find the number of frames on a page.


<!DOCTYPE html>
<html>
<body>
<!-- ww w.j a  v  a  2s .  c o  m-->
<iframe src="http://www.cnn.com"></iframe>
<iframe src="http://www.bbc.com"></iframe>
<iframe src="http://www.example.com"></iframe>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

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

</body>
</html>

The code above is rendered as follows: