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

Q1336 From the child window, how can I check to determine if an opener window is still opened?

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

Q1336 From the child window, how can I check to determine if an opener window is still opened?

If the opener window is closed and the child window has a link that loads into the opener window, a run-time error will occur because the opener window doesn't exist anymore.

Netscape Navigator 3+ and Internet Explorer 4+ support the closed property of the window object, so you could attempt to check that the window still exists, and if not open a new window:

<script language="JavaScript"><!--
function loadIntoOpener(page) {
    if (opener && !opener.closed)
        opener.location='somepage.html';
    else {
        var myWin = window.open(page','','width=100,height=100');
        // trick the window into thinking it was opened by this new window:
        opener = myWin;
    }
}
//--></script>

<a href="javascript:loadIntoOpener('somepage.htm')>text link</a>

Paul writes:

There seem to be problems using window.opener in later versions of Internet Explorer: http://support.microsoft.com/support/kb/articles/Q241/1/09.ASP?LN=EN-US&SD=gn&FR=0. Perhaps you could update your articles to warn people of this.

Feedback on 'Q1336 From the child window, how can I check to determine if an opener window is still opened?'


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.