13.3. The Status LineWeb browsers typically display a status line at the bottom of every window (except for those explicitly created without one), where the browser can display messages to the user. When the user moves the mouse over a hypertext link, for example, the browser usually displays the URL to which the link points. And when the user moves the mouse over a browser control button, the browser may display a simple context help message that explains the purpose of the button. You can also make use of this status line in your own programs. Its contents are controlled by two properties of the Window object: status and defaultStatus. Although web browsers usually display the URL of a hypertext link when the user passes the mouse pointer over the link, you may have encountered some links that don't behave this way -- links that display some text other than the link's URL. This effect is achieved with the status property of the Window object and the onmouseover event handler of hypertext links: <!-- Here's how you set the status line in a hyperlink. -- Note that the event handler *must* return true for this to work. --> Lost? Dazed and confused? Visit the <a href="sitemap.html" onmouseover="status='Go to Site Map'; return true;"> Site Map </a> <!-- You can do the same thing for client-side image maps --> <img src="images/imgmap1.gif" usemap="#map1"> <map name="map1"> <area coords="0,0,50,20" href="info.html" onmouseover="status='Visit our Information Center'; return true;"> <area coords="0,20,50,40" href="order.html" onmouseover="status='Place an order'; return true;"> <area coords="0,40,50,60" href="help.html" onmouseover="status='Get help fast!'; return true;"> </map> The onmouseover event handler in this example must return true. This tells the browser that it should not perform its own default action for the event -- that is, it should not display the URL of the link in the status line. If you forget to return true, the browser overwrites whatever message the handler displays in the status line with its own URL. Don't worry if you do not fully understand the event handler in this example. We'll explain events in Chapter 19. When the user moves the mouse pointer over a hyperlink, the browser displays the URL for the link, then erases the URL when the mouse moves off the hyperlink. The same is true when you use an onmouseover event handler to set the Window status property -- your custom message is displayed while the mouse is over the hyperlink and is erased when the mouse moves off the link. The status property is intended for exactly the sort of transient message we saw in the previous example. Sometimes, though, you want to display a message that is not so transient in the status line -- for example, you might display a welcome message to users visiting your web page or a simple line of help text for novice visitors. To do this, you set the defaultStatus property of the Window object; this property specifies the default text displayed in the status line. That text is temporarily replaced with URLs, context help messages, or other transient text when the mouse pointer is over hyperlinks or browser control buttons, but once the mouse moves off those areas, the default text is restored. You might use the defaultStatus property like this to provide a friendly and helpful message to real beginners: <script> defaultStatus = "Welcome! Click on underlined blue text to navigate."; </script> Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|