spacer
Yehuda Shiran February 7, 2000
Which Frame was Clicked?
Tips: February 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Imagine, in a framed page, you want to decide at the application's top window which child frame has been clicked. One of the ways to do it as follows.

We put an event handler for mouse clicks in the child frame:

<BODY>
  <A HREF="javascript:void(0)" onClick="handleClick()">
     <IMG SRC="doc.gif" 
          WIDTH="50" HEIGHT="50" BORDER="0"></A>
</BODY>
</HTML>

The event handler handleClick() is defined via a function that is included in the top frame:

function handleClick() {
  top.findClickedBox(self);
}

The findClickedBox() function (included in the top frame) finds which frame has been clicked:

function findClickedBox(boxObject) {
 for (var i = 0; i < dim1; i++) {
  for (var j = 0; j < dim2; j++) {
   if (boxObject == top.frames[i].frames[j]) {
    rowFound = j;
    colFound = i;
    if (blockClicking == false)
    if (top.frames[i].frames[j].document.images[0].src.indexOf(blank) == -1)
       revealBox(rowFound, colFound);
    return;
   }
  }
 }
}

We pass the self object from the lowest frame to the top frame. The self object is like an ID by which we can identify the clicked box. We go over all the frames and check for equality between their frame objects and the object passed from the clicked box. Once we determine the clicked frame, we set the rowFound and colFound variables.

Learn more about a frame-based application in 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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags