spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column9


Processing Captured Events

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

The captureEvents() method doesn't have any effect until you assign a function to handle the desired events. To capture all click events on a page, for example, you would need to define a function that handles the event, and then assign the function reference to the event handler. Here's an example:

function processClicks(e) {
  // statements to handle the click events
}

window.captureEvents(Event.CLICK); // click is an event
window.onclick = processClicks; // onclick is an event handler

Without specifying a function to handle click events at the window level, all click events would simply be captured at that level, but would not have any influence because a captured event does not proceed to the intended target event handler. Notice the e parameter in the function's definition. We'll discuss this later in the column.

Since the Event object is not supported by older versions of Navigator, or by Internet Explorer, the window.captureEvents() method requires an object detection statement so it doesn't generate an error on browsers that don't support the Event object. Alternatively, you can check if the browser supports the window.captureEvents() method, or the document.layers object. Here's an example:

function processClicks(e) {
  // statements to handle the click events
}

if (window.captureEvents)
  window.captureEvents(Event.CLICK); // click is an event
window.onclick = processClicks; // onclick is an event handler

See the column "Browser Compatibility" for more information on object detection routines. In this column we won't use any detection routines, for clarity. We'll put them to work in our next column, when we discuss Internet Explorer's event model, and cross-browser event handling.

http://www.internet.com

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


Created: December 16, 1997
Revised: December 16, 1997

URL: http://www.webreference.com/js/column9/process.html