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

Q1255 What do I need to know about window names?

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

Q1255 What do I need to know about window names?

You open a new window in one of three ways:

1. start the browser
Internet Explorer's main browser is _main (undocumented)
Netscape Navigator's main browser is namesless but can be given a name since v3:

<SCRIPT>
window.name="main";
</SCRIPT>

or from a window opened by the main window:

<SCRIPT>
opener.name="main";
</SCRIPT>

2. Using target on frame, href or form
The following:

<A HREF="popup.html" TARGET="popup">open page</A>

will open popup and load page the first time and just load page if popup is already open

3. using window.open

windowHandle = window.open('page.html','popup',properties);

There are exceptions to the name rule - if the "magic" targets/windownames: _top, _self, _blank are used, the opened window will be nameless, but can in situation 3 be given a name:

windowHandle.name = 'popup'; // (a bit pointless...)

You can determine the name of the current window by asking and/or setting it:

if (!self.name) self.name = 'myWindow';

You can get the windowHandle, which you will need to do things like closing or resizing a window by opening the window if you know the name:

winHandle = window.open('','windowName');
winHandle.close();

Be aware that Internet Explorer 3 does not like this lack of page name and will open a blank window.

A trick to close a named window would then be to load a page that closed itself:

window.open('closeit.html','windowName');

Where closeit.html contained:

<BODY onLoad="self.close()"></BODY>

This will produce a warning if you didn't open that window yourself and if the history of that window contain more than one entry.


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.