Capture and release events

Event Capturing – When someone clicks on a button, the onClick event handler of this button is being called. Sometimes to handle certain types of events of the window, document or layer object object, the steps for setting up event capturing are

1) Set up the window to capture all Click events – The event capturing works a little bit differently between the browsers. Use the method captureEvent() for this as

window.captureEvents(Event.CLICK);

To capture several events separate them through a ‘|’ as

window.captureEvents(Event.CLICK | Event.MOVE);

Event Capturing in Internet Explorer:

document.onclick = MyFunction();

2) Define a function that handles the event – The argument ‘e’ is the event object for the event. In IE no need to pass the “e” value.

function MyFunction(e) {

alert(‘Test’); }

3) Define the function as the window’s event handler for that event – The example tells to the browser to call MyFunction() when a Click event occurs.

window.onclick= MyFunction();

Event release – The releaseEvents() method releases all previously captured events. These events can be captured with the Window.captureEvents() method. It’s syntax is as

Syntax Example                 
window.releaseEvents(event)

or

window.releaseEvents(event1 | event2 | eventN)

window.releaseEvents(onclick)

 

Back to Tutorial

Get industry recognized certification – Contact us

Menu