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.

152<br />

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

Tip<br />

windowObject.status<br />

Listing 16-19 (continued)<br />

function scrollMsg() {<br />

// set the number of times scrolling message is to run<br />

if (maxCount == 0) {<br />

maxCount = 3 * msg.length<br />

}<br />

window.status = msg<br />

// keep track of how many characters have scrolled<br />

currCount++<br />

// shift first character of msg to end of msg<br />

msg = msg.substring (1, msg.length) + msg.substring (0, 1)<br />

// test whether we’ve reached maximum character count<br />

if (currCount >= maxCount) {<br />

timerID = 0 // zero out the timer<br />

window.status = “” // clear the status bar<br />

return // break out of function<br />

} else {<br />

// recursive call to this function<br />

timerId = setTimeout(“scrollMsg()”, delay)<br />

}<br />

}<br />

// --><br />

<br />

<br />

<br />

<br />

<br />

Because the statusbar is being set by a standalone function (rather than by an<br />

onMouseOver event handler), you do not have to append a return true statement to<br />

set the status property. The scrollMsg() function uses more advanced <strong>JavaScript</strong><br />

concepts, such as the window.setTimeout() method (covered later in this chapter)<br />

and string methods (covered in Chapter 34 of the <strong>JavaScript</strong> <strong>Bible</strong>). To speed the pace<br />

at which the words scroll across the statusbar, reduce the value of delay.<br />

Many Web surfers (myself included) don’t care for these scrollers that run forever<br />

in the statusbar. Rolling the mouse over links disturbs the banner display.<br />

Scrollers can also crash earlier browsers, because the setTimeout() method eats<br />

application memory in Navigator 2. Use scrolling bars sparingly or design them to<br />

run only a few times after the document loads.<br />

Setting the status property with onMouseOver event handlers has had a checkered<br />

career along various implementations in Navigator. A script that sets the statusbar<br />

is always in competition against the browser itself, which uses the statusbar<br />

to report loading progress. When a “hot” area on a page is at the edge of a frame,<br />

many times the onMouseOut event fails to fire, thus preventing the statusbar from<br />

clearing itself. Be sure to torture test any such implementations before declaring<br />

your page ready for public access.

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

Saved successfully!

Ooh no, something went wrong!