spacer
Yehuda Shiran July 29, 2000
Sharing Functions between Frames
Tips: July 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

When you work with frames, there is always the question how to share functions between frames. It is much simpler than you think. You can access any function in any frame by specifying its full path name, starting from the top frameset. Let's take a frameset with two frames, upper and lower. Here is the frameset definition:

<HTML>
<HEAD>
<TITLE>Demonstrate Function Calls in Frames</TITLE>
</HEAD>
<FRAMESET ROWS="50, 50" FRAMEBORDER="yes" FRAMESPACING="1"> 
  <FRAME SRC="000729c.html" NAME="upper" SCROLLING="no" MARGINHEIGHT="1" MARGINWIDTH="1">
  <FRAME SRC="000729b.html" NAME="lower" SCROLLING="no" MARGINHEIGHT="1" MARGINWIDTH="1">
</FRAMESET>
</HTML>

The upper frame is defined in 000729c.html:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function hello() {
  alert("Hello from the Upper Frame");
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Upper Frame</H1>
</BODY>
</HTML>

And the lower frame is in 000729b.html:

<HTML>
<HEAD>
</HEAD>
<BODY>
<H1>Lower Frame</H1>
<A HREF="javascript:top.upper.hello()">Call hello function from Upper Frame</A>
</BODY>
</HTML>

Notice how we reference hello() from the upper frame: top.upper.hello(). For more on frames, go to Column 37, JavaScript and Frames, Part II - The Famous Memory Game.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business