15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

188<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Event handlers<br />

onAfterPrint<br />

onBeforePrint<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓<br />

Example<br />

The following script fragment assumes that the page includes a DIV element<br />

whose style sheet includes a setting of display:none as the page loads.<br />

Somewhere in the Head, the print-related event handlers are set as properties:<br />

function showPrintCopyright() {<br />

document.all.printCopyright.style.display = “block”<br />

}<br />

function hidePrintCopyright() {<br />

document.all.printCopyright.style.display = “none”<br />

}<br />

window.onbeforeprint = showPrintCopyright<br />

window.onafterprint = hidePrintCopyright<br />

onBeforeUnload<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓<br />

Example<br />

The simple page in Listing 16-43 shows you how to give the user a chance to stay<br />

on the page.<br />

Listing 16-43: Using the onBeforeUnload Event Handler<br />

<br />

<br />

onBeforeUnload Event Handler<br />

<br />

function verifyClose() {<br />

event.returnValue = “We really like you and hope you will stay longer.”<br />

}<br />

windowObject.onBeforeUnload

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

Saved successfully!

Ooh no, something went wrong!