Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Adding Link Descriptions

Some users will undoubtedly prefer traditional hyperlinks to the navigation bar. To make these links more friendly, you can display descriptions of them on the status line when the user moves the mouse pointer over them.

You can accomplish this easily with onMouseOver event handlers. When the user moves the mouse over a link, this event will call a function to display the appropriate message on the status line. For example, the following HTML defines a link with a friendly status line:

<a HREF="order.html"
onMouseOver="window.status='Allows you to order products';return true"
onMouseOut="window.status=''">
Order form</a>

This sets the value of window.status to display the message. In addition, the true value is returned; this is necessary to override the normal action (displaying the URL) for the status line. The onMouseOut event handler clears the status line when the mouse pointer moves off the link.

The following shows the result of adding onMouseOver functions to the links in the original version of the FSC Software page. The page is shown in action in Figure 21.2, with the mouse pointer currently over the Spreadsheet link.

21fig02.jpg

Figure 21.2 The HTML document with link descriptions.

<ul>
<li><a HREF="spread.html"
onMouseOver="window.status='Spreadsheet Information';return true"
onMouseOut="window.status=''">
Fictional Spreadsheet 7.0</a>
<li><a HREF="word.html"
onMouseOver="window.status='Word Processor Info';return true"
 onMouseOut="window.status=''">
Fictional Word Processor 6.0</a>
 <li><a HREF="data.html"
 onMouseOver="window.status='Database Information';return true"
  onMouseOut="window.status=''">
Fictional Database 7.0</a>
</ul>

Share ThisShare This

Informit Network