spacer
Yehuda Shiran December 29, 2000
The Navigator Event Model
Tips: December 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

In order to understand the new event handling strategy in Netscape 6, you need to refresh your knowledge of how it is done in Netscape Navigator 4.x. The main idea is an event is falling inward, from the window object, through the document object and any other intermediate objects, until it reaches the target object. Netscape introduced the concept of event capturing. You can intercept an event at any object, before it reaches the final target element. The following piece of code creates a button event handlers for both the button and the window object. Notice how we capture the click event at the window object:

<SCRIPT LANGUAGE="JavaScript">
<!--

function buttonClicked(e) {
  alert("You clicked a button.");
  return true;
}

function windowClicked(e) {
  alert("You clicked in the window");
  return true;
}
if (window.captureEvents)
  window.captureEvents(Event.CLICK); // CLICK is an event
window.onclick = windowClicked; // onclick is an event handler

// -->
</SCRIPT>
<FORM NAME="myForm">
<INPUT TYPE="button" VALUE="click here" NAME="myButton" onClick="buttonClicked()">
</FORM>
Click the button below, in Netscape Navigator 4.x. You can see that the click event has been captured successfully, before it reaches the button. You can also observe that the click event was really intended for the button, otherwise every click in the window (outside the button) would have triggered an alert box:

Learn more about the event model in Netscape Navigator 4.x in Column 9, The Navigator Event Model.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Eight Reasons Why Oracle's Acquisition of Sun isn't All Bad · The New Threat to Data Center Security: The Underground Economy · Buyers' Guide: Choosing a Payment Gateway Provider