Sample Scripts
How about some useful scripts to get you started? This section offers several scripts you can copy into your web pages.
Status Line Messages
Probably the simplest JavaScript you can add to your site is a message that appears in the status bar (the bar at the bottom that shows URLs or says “Document: Done”). You can use this bar to display a message when the user places the mouse over a link. To do this simply add a little JavaScript to a standard anchor tag. You don’t even need to declare a script. Non-JavaScript-compatible browsers will simply ignore the code. Here’s how you do it:
<A HREF="mozart.com" onMouseOver="window.status='A study of Mozart's operas'; return true;">Mozart</A>
The above code displays the text “A study of Mozart’s operas” when the user puts the cursor over the Mozart link. To use this code on your site, just replace the text between the single quotes (and the URL and hypertext, of course).
Opening a New Window
We detailed the code for opening a new window earlier in the chapter, so we’ll just take a quick look here at which code needs to be replaced to use this script on your site. The code again:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!---
function openWin(URL) {
aWindow=window.open(URL,"thewindow","toolbar=no,width=350,
height=400,status=no,scrollbars=yes,resize=no,menubar=no");
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<P><A HREF="javascript:openWin('mozart.html');">Mozart</A></P>
<P><A HREF="javascript:openWin('wagner.html');">Wagner</A></P> ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access