Javascript Browser Window frames Property

Introduction

Change the location of the first <iframe> element in the current window:

window.frames[0].location = "https://www.java2s.com/jsref/";

Click the button to change the location of the first iframe element.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>
<br><br>

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

<script>
function myFunction() {/*ww  w.j  a  v  a2s.  co  m*/
  window.frames[0].location = "https://www.java2s.com/jsref/";
}
</script>

</body>
</html>

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

The <iframe> elements can be accessed by index numbers. The index starts at 0.

Use frames.length to find the number of frames.

This property is read-only.




PreviousNext

Related