spacer
Yehuda Shiran December 31, 1999
Frame Arrays
Tips: December 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

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

Often times you have an application that is based on an array of frames and the user is asked to click on one of them. How can you detect which frame has been clicked? The trick is very simple. Upon clicking, you pass the frame object to the parent. Then, in the parent, you search for the frame with the same object value. Here are the steps, one by one.

First, we put an event handler for mouse clicks in each of the child frames:


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

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 had 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;
        do something with the identified frame
        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 64 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. We then do something with the frame and return.

Learn how to use this trick in a memory game programming, in Column 37, JavaScript and Frames, Part II.


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