You are here: irt.org | FAQ | JavaScript | Window | Q683 [ previous next ]
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.