spacer

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

home / experts / javascript / column9


Processing Captured Events

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

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, 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


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

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