Share this Page URL

Chapter 17. The Programmable Page: Addin... > Some JavaScript Examples - Pg. 202

The Programmable Page: Adding JavaScripts to Your Pages 202 One of the most requested JavaScript examples is a script that not only displays a message in the browser's status bar, but also scrolls the message from right to left. This is a complex procedure, as you can see in the next example, but you can safely ignore most of the code. You'll find everything on this book's CD in the file named jsscroll.htm, which also provides instructions for customizing the status bar message. Figure 17.8 shows the page in Netscape. <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- // Use the following three variables to set up the message: var msg = "Enter your status bar message here" var delay = 50 var startPos = 100 // Don't touch these variables: var timerID = null var timerRunning = false var pos = 0 // Crank it up! StartScrolling() function StartScrolling(){ // Make sure the clock is stopped StopTheClock() // Pad the message with spaces to get the "start" position for (var i = 0; i < startPos; i++) msg = " " + msg // Off we go... DoTheScroll() } function StopTheClock(){ if(timerRunning) clearTimeout(timerID) timerRunning = false } function DoTheScroll(){ if (pos < msg.length) self.status = msg.substring(pos, msg.length); else pos=-1; ++pos timerRunning = true timerID = self.setTimeout("DoTheScroll()", delay) } //--> </SCRIPT>