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

Q389 How can I test for the existence of a function in another frame?

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

In Netscape Navigator 4 you can check the existence of a function by using:

if (parent.framename.functionname)
    alert('Exists');

However this does not work in Netscape Navigator 2.

A better solution is to set a variable that you can interrogate:

<frameset rows="50%,*">
<frame src="aFrame.htm" name="aFrame">
<frame src="bFrame.htm" name="bFrame">
</frameset>

in aFrame.htm:

<script language="JavaScript"><!--
var myFunction = 'someFunction';
function someFunction() { alert('Hello World') }
//--></script>

in bFrame.htm:

<script language="JavaScript"><!--
function find(what) {
    for (var i=0;i<parent.frames.length;i++) {
         if (parent.frames[i].name == what)
             if (parent.frames[i].myFunction == 'someFunction')
                 return true;
    }
    return false;
}
//--></script>

<form>
<input type="button" value="Test" onClick="if (find('aFrame')) parent.aFrame.someFunction()">
</form>

©2018 Martin Webb