HTML and CSS Reference
In-Depth Information
The event object is accessed within an event handler function, using the window object as
var evnt = window.event;
The event object is a property of the window object. In this example, a reference to the
event object is assigned to a variable but also can be used directly. Within the context of the
current event handler, the event object contains the pertinent information—that is to say, the
respective properties are set. For example, in a keydown event, the details of the keyboard
state are available, but the mouse buttons aren't because they aren't relevant to a keydown
In Internet Explorer, the window event is the method required to access the event ob-
ject. However, in some browsers, the event object is passed to the event function as a
Declarative event handling
Handling events declaratively in the HTML markup is possible by setting up an event handlers
line within the HTML elements. This is effectively no different than assigning a value to any
other property or attribute of the HTML element. Look at the following HTML sample:
function onloadHandler() {
alert("hello event.");
<body onload="onloadHandler();">
In this HTML markup, the onload attribute of the body element is assigned JavaScript to
run. The onload event fires when the document itself is fully loaded into the browser. When
the document is loaded, the onload event fires, which calls the onloadHandler function and in
turn shows the alert box. Any events that will be looked at through this objective can be set
up this way directly in the HTML markup. Next, you see how to set up events programmati-
cally by assigning the function to the event property in JavaScript.
Search WWH ::

Custom Search