09.02.2015 Views

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

DOM Traversal Methods - MarkMail

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Event <strong>Methods</strong><br />

.unload()<br />

Binds an event handler to the unload JavaScript event.<br />

.unload(handler)<br />

Parameters<br />

• handler: A function to execute when the event is triggered.<br />

Return Value<br />

The jQuery object, for chaining purposes.<br />

Description<br />

This handler is a shortcut for .bind('unload', handler).<br />

The unload event is sent to the window element when the user has navigated away<br />

from the page. This could mean one of many things. The user could have clicked on<br />

a link to leave the page, or typed in a new URL in the address bar. The forward and<br />

back buttons will trigger the event. Closing the browser window will cause the event<br />

to be triggered. Even a page reload will first create an unload event.<br />

Any unload event handler should be bound to the window object:<br />

$(window).unload(function() {<br />

alert('Unload event was triggered.');<br />

});<br />

After this code executes, the alert will be displayed whenever the browser leaves the<br />

current page.<br />

It is not possible to cancel the unload event with .preventDefault(). This event is<br />

available so that scripts can perform cleanup when the user leaves the page.<br />

.error()<br />

Binds an event handler to the error JavaScript event.<br />

.error(handler)<br />

[ 106 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!