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

Q380 How do I find if a particular frame exists before attempting to use a function inside that frame?

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

Try:

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

In aFrame.htm:

<script language="JavaScript"><!--
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)
             return true;
    }
    return false;
}
//--></script>

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

©2018 Martin Webb