Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Frame | Q380 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.