Section 14.6. Scripting the Status Line


14.6. Scripting the Status Line

Web browsers typically display a status line at the bottom of every window in which the browser can display messages to the user. When the user moves the mouse over a hypertext link, for example, a browser typically displays the URL to which the link points.

In old browsers, you can set the status property to specify text that the browser should temporarily display in the status line. This property was typically used when the user hovered the mouse over a hyperlink to display a human-readable description of the linked document instead of the machine-readable URL of the document. Code that did this typically looked like this:

 Confused? Try the <a href="help.html" onmouseover="status='Click here for help!'; return true;"> Online Help</a>. 

When the mouse moves over this hyperlink, the JavaScript code in the onmouseover attribute is evaluated. It sets the status property of the window and then returns TRue to tell the browser not to take its own action (displaying the URL of the hyperlink).

This code snippet no longer works. Code like this was too often used to intentionally deceive users about the destination of a link (in phishing scams, for example), and modern browsers have disabled the ability to set the status property.

The Window object also defines a defaultStatus property that specifies text to be displayed in the status line when the browser doesn't have anything else (such as hyperlink URLs) to display there. defaultStatus still works in some browsers (but not all: Firefox 1.0, for example, disables the defaultStatus property along with the status property).

Historically, one use of the defaultStatus property was to produce status line animations. In the old days, when document content was not yet scriptable, but the defaultStatus property and the setInterval( ) method were available, web developers proved unable to resist the temptation to create a variety of distracting and gaudy marquee-style animations that scrolled a message across the status line. Fortunately, those days are gone. There are still occasional reasons to use the status line, however, and even to use it with setInterval( ), as Example 14-6 demonstrates.

Example 14-6. A tasteful status-line animation

 <script> var WastedTime = {     start: new Date( ),   // Remember the time we started     displayElapsedTime: function( ) {         var now = new Date( );  // What time is it now         // compute elapsed minutes         var elapsed = Math.round((now - WastedTime.start)/60000);         // And try to display this in the status bar         window.defaultStatus = "You have wasted " + elapsed + " minutes.";     } } // Update the status line every minute setInterval(WastedTime.displayElapsedTime, 60000); </script> 




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net