window.frames is a collection of all of the frames in the current page. It doesn't distinguish between frames and iframes.

It doesn't matter whether there are frames on the page or not, window.frames always exists and points to window.

window.frames === window //true

So to check if there are any frames on the page, use the length property.

frames.length //1

Each frame contains another page which has its own global window object. Imagine you have a page with one iframe.

<iframe name="myframe" src="about:blank" />

To get access to the iframe's window, you can do any of these.

Access child properties from parent

We can access properties of the child frame from the parent page

For example, you can reload the frame like this.

Accessing child from parent

From inside the child you can access the parent:

frames[0].parent === window // true
Using a property called top, you can access the topmost page (the one that contains all the other frames) from within any frame:
window.frames[0] === window //true
window.frames[0] === //true
window.frames[0] === top //true

In addition, self is the same as window.

self === window //true
frames[0].self == frames[0].window //true

If a frame has a name attribute, you can also access the frame by name, not only by index.

window.frames['myframe'] === window.frames[0] //true
Related Tutorial
Follow Us #
Contents +