JavaScripTools Manual

JavaScriptUtil

Manipulating events

Many browsers (specially Internet Explorer) do not follow the standards for event handling. So, there are some functions to perform basic operations on events.

The observeEvent function adds an event handler to a given element. It receives the object, the event name and a handler function. The name must be in the W3C standard, like blur, keypress, etc. The handler function may safely refers to the object as this on Internet Explorer (something that, without a workarround, is not possible). On version 2.1, this function had the same name as the standard addEventListener function, and replaced the existing one. So, it is now called observeEvent. If you have relied uppon it and don't need to observe window events, you can simply do addEventListener = observeEvent (after importing JavaScriptUtil, of course :-)

typedCode is function that returns the keyCode for a given event. If you need the typed character, use String.fromCharCode(typedCode(event)).

preventDefault is used to not allowing the default action to execute. Example: inside a keypress event, if you do preventDefault(event), the key won't be appended to the control text.

Finally, stopPropagation stops an event to propagate to other objects that could receive the event. Example: nested divs. When you click the outermost, the event propagates to the others, until the last one (the document also receives the event).




Previous:
Manipulating caret and selection on input fields
Table of Contents Next:
The Map class