|
Random Status Bar Messages In this version, you can define multiple messages and the script displays them randomly. Here are the instructions:
<SCRIPT LANGUAGE="JavaScript">
<!--
// Use the following variable to
// specify the number of messages
var NumberOfMessages = 4
var messages = new BuildArray(NumberOfMessages)
// Use the following variables to
// define your messages:
messages[1] = "Message A"
messages[2] = "Message B"
messages[3] = "Message C"
messages[4] = "Message D"
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()
// Pick the first message at random
PickRandomMessage()
// 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{
PickRandomMessage()
pos=-1
}
++pos
timerRunning = true
timerID = self.setTimeout("DoTheScroll()", delay)
}
function PickRandomMessage(){
// Use the time (i.e., seconds) to get a random number
var d = new Date()
var secs = d.getSeconds()
var rnd = (secs % messages.length) + 1
msg = messages[rnd]
// Pad the message with spaces
// to get the "start" position
for (var i = 0; i < startPos; i++) msg = " " + msg
}
function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this[i] = null}
return this
}
//-->
</SCRIPT>
Copyright © 1995-2008 Paul McFedries and Logophilia Limited |