The frames
property returns an array of all the frames
including iframes in the current window.
The frames property is supported in all major browsers.
frames |
Yes | Yes | Yes | Yes | Yes |
var v = window.frames
Returns an array representing listing all of the frames in the current window.
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: