You are here: irt.org | FAQ | JavaScript | Window | Q1336 [ previous next ]
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.