Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q782 Is it possible to get access to a named window, opened with target=name?

You are here: irt.org | FAQ | JavaScript | Window | Q782 [ previous next ]

If you attempt to open the window again with the same name in the second parameter of the windows open method, you should be able to get the windows handle:

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

The first parameter (the url) is passed as an empty string, which should result in the contents of the window remaining unchanged. Although JavaScript The Definitive Guide edition 2 says the url is mandatory in Internet Explorer 3, yet in JavaScript The Definitive Guide edition 3 it says:

url: an optional string that specifies the URL to be displayed in the new window. If this argument is omitted, or it the empty string is specified, the new window does not display a document

In Internet Explorer 3 the above code will result in a blank new window being opened.

Thanks to Dave May for pointing out: "You cannot get the handle if the page is not on the same host as its opener"

Note that this will create a new window if it was not already opened, or if it had been subsequently closed. You can test to see if a window is closed using:

var winHandle = null;

// some time later:

if (winHandle && winHandle.closed) {
    // do nothing
}
else {
    winHandle = window.open('','windowName')
}

Feedback on 'Q782 Is it possible to get access to a named window, opened with target=name?'

©2018 Martin Webb