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.

158<br />

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

Example<br />

See Listing 16-4 (for the window.closed property), which provides an elaborate,<br />

cross-platform, bug-accommodating example of applying the window.close()<br />

method across multiple windows.<br />

confirm(“message”)<br />

windowObject.confirm()<br />

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

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓<br />

Example<br />

The example in Listing 16-23 shows the user interface part of how you can use a<br />

confirm dialog box to query a user before clearing a table full of user-entered data.<br />

The line in the title bar, as shown in Figure 2-7, or the “<strong>JavaScript</strong> Confirm” legend in<br />

earlier browser versions, cannot be removed from the dialog box.<br />

Listing 16-23: The Confirm Dialog Box<br />

<br />

<br />

window.confirm() Method<br />

<br />

function clearTable() {<br />

if (confirm(“Are you sure you want to empty the table?”)) {<br />

alert(“Emptying the table...”) // for demo purposes<br />

//statements that actually empty the fields<br />

}<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Figure 2-7: A <strong>JavaScript</strong> confirm<br />

dialog box (IE5/Windows format)

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

Saved successfully!

Ooh no, something went wrong!