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.

window.onbeforeunload = verifyClose<br />

<br />

Chapter 2 ✦ Window and Frame Objects (Chapter 16)<br />

<br />

<br />

onBeforeUnload Event Handler<br />

<br />

Use this button to navigate to the previous page:<br />

<br />

Go Back<br />

<br />

<br />

<br />

onHelp<br />

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

Compatibility ✓ ✓ ✓<br />

Example<br />

The following script fragment can be embedded in the IE5-only modeless dialog<br />

box code in Listing 16-44 to provide context-sensitive help within the dialog box.<br />

Help messages for only two of the form elements are shown here, but in a real application<br />

you add messages for the rest.<br />

function showHelp() {<br />

switch (event.srcElement.name) {<br />

case “bgColor” :<br />

alert(“Choose a color for the main window\’s background.”)<br />

break<br />

case “name” :<br />

alert(“Enter your first name for a friendly greeting.”)<br />

break<br />

default :<br />

alert(“Make preference settings for the main page styles.”)<br />

}<br />

event.returnValue = false<br />

}<br />

window.onhelp = showHelp<br />

Because this page’s help focuses on form elements, the switch construction<br />

cases are based on the name properties of the form elements. For other kinds of<br />

pages, the id properties may be more appropriate.<br />

189<br />

windowObject.onHelp

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

Saved successfully!

Ooh no, something went wrong!