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

Q1038 Is there a way for a popup window to check if the URL of the main window has changed to a URL on a different server without causing an error?

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

You should be able to do this with an image.

If in you opener window you defined an image using:

<script language="JavaScript"><!--
if (document.images)
    var myUniqueReference = new Image();
//--></script>

Then in the popup window you should be able to detect this using:

<script language="JavaScript"><!--
if (opener.myUniqueReference ? true : false)
    alert('My window');
else
    alert('Not my window');
//--></script>

This should work even if the opener now contains a document from another server.

©2018 Martin Webb