15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

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

hidden with the popup global variable returned to its original, null value. But if the<br />

value is other than zero, then the inner text of the SPAN is set to the decremented<br />

value (with a leading zero), and the setTimeout() method is called upon to reinvoke<br />

the countDown() function in one second (1000 milliseconds).<br />

Listing 16-49: Hiding and Showing a Pop-up<br />

<br />

<br />

popup Object<br />

<br />

var popup<br />

function initContent() {<br />

if (popup && !popup.isOpen) {<br />

var popBody = popup.document.body<br />

popBody.style.border = “solid 3px red”<br />

popBody.style.padding = “10px”<br />

popBody.style.fontSize = “24pt”<br />

popBody.style.textAlign = “center”<br />

var bodyText = “This popup will self-destruct in “<br />

bodyText += “05”<br />

bodyText += “ seconds...”<br />

popBody.innerHTML = bodyText<br />

}<br />

}<br />

function countDown() {<br />

if (popup && popup.isOpen) {<br />

var currCount = parseInt(popup.document.all.counter.innerText, 10)<br />

if (--currCount == 0) {<br />

popup.hide()<br />

popup = null<br />

} else {<br />

popup.document.all.counter.innerText = “0” + currCount<br />

setTimeout(“countDown()”, 1000)<br />

}<br />

}<br />

}<br />

function selfTimer() {<br />

popup = window.createPopup()<br />

initContent()<br />

popup.show(200,200,400,100,document.body)<br />

setTimeout(“countDown()”, 1000)<br />

}<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

203<br />

popupObject.hide()

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

Saved successfully!

Ooh no, something went wrong!