Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q683 How do I iterate over all the opened windows?

irt.org | Knowledge Base | JavaScript | Window | Q683 [ previous next ]

Q683 How do I iterate over all the opened windows?

With extreme difficulty as there is not an object that holds all the open windows. When you open a window in JavaScript you use the following syntax:

windowHandle = window.open(url, name, features, replace)

The windowHandle holds a reference to the new window. So from the window that created the new window you can refer to the new window using the windowHandle, e.g. alert(windowHandle.title). You can refer back to the creating window (the opener window) from the new window by using the new windows opener property, e.g. alert(opener.title). This is the only means of getting information between windows.

If you need to maintain information of all the open windows that you create then you'll need to create your own code to handle this for you. For example say we create a new window from the main window, and then from new window we create yet another window. In document1.htm:

<SCRIPT LANGUAGE="JavaScript"><!--
windowHandle2 = window.open('document2.htm');
//--></SCRIPT>

and then in document2.htm:

<SCRIPT LANGUAGE="JavaScript"><!--
opener.windowHandle3 = window3 = window.open('document3.htm');
//--></SCRIPT>

Then the main window holds a reference to both of the new windows, the first new window holds a reference to the second new window, and both the new windows hold a refernce (opener) to their openers.

Feedback on 'Q683 How do I iterate over all the opened windows?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.