WebReference.com - Part 2 of chapter 5 from Creating Applications with Mozilla. From O'Reilly (1/5).
Creating Applications with Mozilla, Chapter 5: Scripting Mozilla
[The following is a continuation of our series of excerpts from chapter 5 of the O'Reilly title, Creating Applications with Mozilla.]
Events are input messages that pass information from the user interface to the application code. Capturing this information, or event handling, is how you usually tell scripts when to start and stop.
<window onload="dump('this window has loaded\n');" /> <button label="onclick-test" onclick="dump('The event handler onclick has just been used\n');" /> <button label="oncommand-test" oncommand="dump('The event handler oncommand has just been used\n');" /> <menulist id="custom" onchange="doMyCustomFunction( );" />
While the window and button events in Example 5-5 carry out some inline script, there is a variation with the
onchange handler attached to the
src attribute on a
A large basic set of event handler attributes is available for use on XUL elements (and HTML elements). Appendix C has a full listing of these events along with explanations. The following subset shows the potential for script interaction when the UI uses event handlers:
onabort onblur onerror onfocus onchange onclick oncontextmenu ondestroy onload onpaint onkeydown onkeypress onkeyup onunload onmousemove onmouseout onmouseover onmouseup onmousedown onrest onresize onscroll onselect onsubmit
Some of these event handlers work only on particular elements, such as
window, which listens for the
load event, the
paint event, and other special events.
To see all event handler attributes on a particular element, you can execute the short script in Example 5-6, which uses the
The function you added in Example 5-4 is also an example of event handler code in an application's interface.
Created: September 26, 2002
Revised: September 26, 2002