|
|
|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98
Mouse Events
These events are the events triggered in response to mouse movements or mouse button presses. A few of these are familiar events, having been part of the Document Object Model before; some are new as a result of Dynamic HTML.
- onclickThis event is normally triggered when the user presses and releases the left mouse button. It can also occur when the user presses certain keys, such as Enter and Esc, in an HTML form.
A JavaScript onclick event handler is shown later. This event handler is triggered when a mouse click is recorded anywhere in the current document, and it uses the event object to pop up an Alert box to give the name of the HTML tag in which the click occurred.
<SCRIPT FOR=document EVENT=onclick LANGUAGE=JAVASCRIPT>
alert(Clicked in + window.event.srcElement.tagName);
</SCRIPT>
- ondblclickThis event is triggered when the user clicks twice over an object. If an event handler assigned to this event returns a false value, it cancels the default action.
- ondragstartThis event is triggered when the user begins a drag selection.
- onmousedownThis event is triggered when the user presses the mouse button.
- onmousemoveThis event is triggered when the mouse is moved.
- onmouseoverThis event is triggered when the mouse is moved into an object. It occurs when the mouse first enters the object and does not repeat unless the user moves the mouse out and then back in.
- onmouseoutThis event is triggered when the user moves the mouse out of a given element. When the user moves the mouse pointer into an element, one onmouseover event occurs, followed by one or more onmousemove events as the user moves the pointer within the element; and finally, one onmouseout event occurs when the user moves the pointer out of the element.
- onmouseupThis event is triggered when the mouse button is released.
Note that some of the events described in the preceding list actually trigger multiple events. The events leading to a valid ondblclick event, for example, occur in the following steps:
- 1. onmousedown
- 2. onmouseup
- 3. onclick
- 4. onmousedown
- 5. onmouseup
- 6. ondblclick
Keystroke Events
New to Microsoft Internet Explorer with its support for Dynamic HTML are events triggered by user keypresses. Three general purpose events and one special purpose event respond to keys:
- onkeydownThis event is triggered when the user presses a key and returns the number of the keycode for the key pressed. An event handler assigned to service this event can return a different value and override the original key.
- onkeyupTriggered when the user releases a key.
- onkeypressThe last event triggered for a valid key press: First the onkeydown event is triggered, and then onkeyup, and then onkeypress. Event handlers assigned to any of these three events can be used to intercept, override, and/or nullify the actual key pressed.
- onhelpThis event is triggered when the user presses the F1 key or clicks the Help key on the Web browser.
Focus Events
These events are used to follow the focus of the cursor around the HTML document. They can be used to good effect when performing HTML form validation but can also be used with non-form elements.
- onfocusThis event is triggered when the element in question receives the input focus.
- onblurThis event is triggered when an object loses the input focus.
- onchangeThis event is triggered when the contents of the object, normally a text or text area HTML form field, are changed.
Note that this event is triggered only after the object has lost focus and if its contents have changed. If an event handler exists for the onblur event for the same object, the onchange event is triggered and executed first.
<MARQUEE> Events
Although Microsofts <MARQUEE> tag is a nonstandard HTML element, it has come into increasing use. Microsofts Dynamic HTML implementation includes three events specifically tied to that tag:
- onbounceThis event can only be triggered when the contents of the <MARQUEE> tag are set to alternately scroll one way and then the other. It is actually triggered when the scrolling content changes direction.
- onstartThis event is triggered when a scrolling loop begins or, for alternate behavior, when a bounce cycle begins.
- onfinishThis event is triggered when a scrolling loop ends.
Page Events
In addition to the onload event, which has existed in the past and is triggered when a Web page is completely loaded, Dynamic HTML adds a couple of other events associated with loading and unloading documents into your Web browser. This enables you to set the entrance and exit behaviors of the Web browser for a given document.
- onloadThis event is triggered after the Web browser loads the given object. It is normally used with the HTML document itself, but can also be applied to images, applets, and any other Web browser object loaded along with the HTML document itself.
- onbeforeunloadThis event is triggered prior to an HTML document being unloaded. By attaching an event handler to this event, you can give the user a chance to change his or her mind and remain on the current page.
- onunloadThis event is triggered immediately before the current page is unloaded. Unlike the onbeforeunload event, after this event is triggered it is too late to prevent the user from leaving the page.
|