Accessing the Status Bar


One of the most common uses for the properties of the window object is to display text in the browser's status bar, using the window.status object. You also can set default text in the status bar (which is displayed when the browser loads, and before and after the mouse moves over links) using the window.defaultStatus property.

In fact, we've already seen how this works as far back as Chapter 4, "Handling the Browser Environment." This example displays Hello! and Good Bye! in the status bar as the user moves the mouse over a link (note that both functions here return a value of true to make sure the browser does not perform its default action of displaying the link's URL; this is Listing 04-03.html on the web sitenote also that some versions of Netscape Navigator 6 will not let you display anything but a hyperlink's URL when the mouse rolls over that hyperlink):

 <HTML>      <HEAD>          <TITLE>Using the Status Bar</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  function sayHello() {   window.status = "Hello!"   return true   }   function sayGoodBye() {   window.status = "Good Bye!"   return true   }  // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Using the Status Bar</H1>  <A HREF="http://www.starpowder.com"   ONMOUSEOVER="return sayHello()"   ONMOUSEOUT="return sayGoodBye()">Here's my site!</A>  </BODY>  </HTML> 

You can see the results of this code in Chapter 4, Figure 4.5.

Here's another popular way of handling messages in the status baryou can scroll such messages using the handy window object's setTimeout method (discussed in the next chapter). You pass setTimeout an expression to execute and a time, in milliseconds , to wait before evaluating that expression. In this case, I can use setTimeout to call a function recursively (that is, have the same function call itselfsee "Handling Recursion" in Chapter 3, "The JavaScript Language: Loops, Functions, and Errors"), taking one character off the beginning of the status bar text and putting it on the end of the text with the String method substring (which we'll cover in depth in Chapter 18, "The Date , Time , and String Objects") like this:

(Listing 07-01.html on the web site)
 <HTML>      <HEAD>          <TITLE>Scrolling Status Bar Text</TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--             var text = "Hello from JavaScript! Hello from JavaScript! "  function scroller()   {   window.status = text   text = text.substring(1, text.length) + text.substring(0, 1)   setTimeout("scroller()", 150)   }  // -->          </SCRIPT>      </HEAD>  <BODY ONLOAD="scroller()">  <H1>Scrolling Status Bar Text</H1>      </BODY>  </HTML> 

Note that I start scrolling the text as soon as the document is loaded, using the <BODY> element's ONLOAD attribute (covered in Chapter 9). Working with the text in the status bar, this makes it appear to scroll, as you can see if you run this example; you can see a static snapshot in Figure 7.1.

Figure 7.1. Scrolling text in the Netscape Navigator's status bar.

graphics/07fig01.gif



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

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