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

Q793 Is there some way I can change the focus to the original window, if the window still exists?

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

In newer browsers (JavaScript 1.1) you can check that a window is still open using:

if (!windowName.closed)

You can therefore make you code more robust with:

<SCRIPT LANGUAGE="JavaScript"><!--
function focusOpener() {
    opener.focus();
}
//--></SCRIPT>

<SCRIPT LANGUAGE="JavaScript1.1"><!--
function focusOpener() {
    if (!opener.closed) {
        opener.focus();
    }
}
//--></SCRIPT>

<A HREF="javascript:focusOpener()">show main window</A>

The second definition of focusOpener() overrides the first in browsers that support JavaScript 1.1 or better, for other browsers the more unreliable approach is used.

©2018 Martin Webb