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

Q1111 How can I tell from one frame when another frame's url changes and have it act accordingly?

You are here: irt.org | FAQ | JavaScript | Frame | Q1111 [ previous next ]

Only if the url in the other frame comes form the same server as the page that 'snoops' - otherwise a security error occurs.

Have this in the frameset:

<html>
<head>

<script language="JavaScript"><!--
saveUrl = '';

function hasChanged() {
    var currentUrl = top.otherframe.location.href;
    if (currentUrl != top.saveUrl && top.saveUrl != '') {
        alert('Page changed from ' + saveUrl + '\nto ' + currentUrl);
    }
    saveUrl = currentUrl;
    setTimeout('top.hasChanged()',10000); // test every 10 seconds
}
//--></script>
</head>

<frameset onLoad ="top.hasChanged()">
...
</frameset>

The script can also be in one frame, then "top." must be changed to "top.framename." everywhere but the onLoad stays unchanged.

Feedback on 'Q1111 How can I tell from one frame when another frame's url changes and have it act accordingly?'

©2018 Martin Webb