Event mechanisms are good way to add functionality to the user interaction. Rather than let the browser handle the user's mouse clicks, you can intervene with JavaScript and add all kinds of sophisticated behavior to each user-driven trigger.
An event is simply a trigger generated manually by the user or as a consequence of something happening in the host environment. Events can be generated at the following times:
When a user clicks on something
When something finished being loaded from the web server
When an error occurs
When a Java exception happens
When a timer runs out
When a page is closed
When a page needs to be refreshed
When a plugin calls back to its parent page
When a property changes while it has a watch() active on it
Server-side initiation
Each of these is associated with a handler. Most of them are triggered as HTML intrinsic events.
By default, the triggers behave as if a null handler is assigned to the event so it appears that nothing happens when the event fires. It's likely that inside the interpreter, the event is processed and simply calls a handler that returns straight away. You can replace that handler whenever you want to as the page content is processed.
MSIE version 4 implements virtually every event on every object. We describe each of those events in its own topic.
Trying to integrate both MSIE and Netscape browser event models into a single unified concept is something that is vexing the W3C experts as they deliberate over higher level functionality in the DOM. This is not likely to be resolved for some time.
Even the documentation from Netscape is inconsistent as to which event and object combinations are supported on different platforms, and you should attempt to test any portable scripts and event handlers on a variety of system configurations before deployment. Netscape 6.0 is far more standards based and consistent with MSIE as far as event handling is concerned. It implements the DOM level 2 event support. Documentation on the new version is still scarce, even on the Netscape web sites.
Draft DOM level 3 documents describing an MSIE-like event model have been published and the relevant topics are included here because that event model is supported by Netscape 6.
You may be able to establish what events are supported by an object if you write an inspection script to enumerate and print out the names of any properties of that object. You should see place holder properties for each event handler. These will be undefined unless you have registered a handler function with them.
See also: | DOM Events, Script execution |
Prev | Home | Next |
Event-driven model | Up | event |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |