|
Q389 How can I test for the existence of a function in another frame?
irt.org | Knowledge Base | JavaScript | Frame | Q389 [ previous next ]
Q389 How can I test for the existence of a function in another frame?
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>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.