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

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

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

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

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.


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.