Javascript Reference - Window frames Property








The frames property returns an array of all the frames including iframes in the current window.

Browser Support

The frames property is supported in all major browsers.

frames Yes Yes Yes Yes Yes

Syntax

var v = window.frames

Return Value

Returns an array representing listing all of the frames in the current window.





Example

The following code shows how to Find the number of frames on a page, and change the src property of every frame element to "example.com".


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<iframe src="http://www.cnn.com"></iframe>
<iframe src="http://www.google.com"></iframe>
<iframe src="http://www.nytimes.com"></iframe>
<script>
function myFunction() {<!-- w  w  w . j a v  a2s . co  m-->
    for (var i = 0; i < frames.length; i++) {
        frames[i].location = "http://www.example.com"
    }
}
</script>

</body>
</html>

The code above is rendered as follows: