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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint