Window frames Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window frames

Description

The frames property returns an array-like object for all <iframe> elements in the current window.

This property is read-only.

Return Value

The following code shows how to returns a reference to the Window object, representing all frames in the current window. It changes the location of the first <iframe> element (index 0) in the current window:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>
<br><br>

<iframe src="https://www.cnn.com"></iframe>
<iframe src="https://www.bbc.com"></iframe>
<iframe src="https://www.java2s.com"></iframe>

<script>
function myFunction() {//from w ww.j av  a2 s .  c  o  m
    var frames = window.frames;
    var i;

    for (i = 0; i < frames.length; i++) {
        frames[i].location = "https://www.java2s.com";
    }
}
</script>

</body>
</html>

Related Tutorials