Persistent Random Banners: The Code
Persistent Random Banners
The Code
function refreshDocJSTOD(frequency) {
var max = tips.length;
var dateObj = new Date();
switch(frequency) {
case "month": // 0 - 11
tipIndex = dateObj.getMonth();
break
case "dayOfTheMonth": // 1 - 31
tipIndex = dateObj.getDate() - 1 // 0 - 30
break;
case "dayOfTheWeek": // 0 - 6
tipIndex = dateObj.getDay();
break;
case "hour": // 0 - 23
tipIndex = dateObj.getHours();
break;
case "now": // Default
default:
tipIndex = getRandomIndex(max);
}
tipIndex = tipIndex % max;
document.write(tips[tipIndex]);
}
function getRandomIndex(max) {
var randomNum = Math.random();
randomNum = randomNum * max;
randomNum = parseInt(randomNum);
if(isNaN(randomNum)) randomNum = 0; // for Netscape
return randomNum;
}
Next: The Message Feed
Produced by Yehuda Shiran and Tomer Shiran
Created: March 27, 2000
Revised: April 26, 2000
URL: https://www.webreference.com/js/column60/5.html