|
|
|
<head>
<script language="javascript">
/*
Define global variables out side of function
so they do not get repeatedly set
*/
var count = 0//Incremented every time the function is called
var color1 = "black" //The two colors that are alternated
var color2 = "white"
var colorChangeDelay = 10 //The delay at that is used before the function calls itself
var timerId //The the timer id is used used to allow the thread to be cancelled
var maxAlternations = 20 //The Maximum number of times the function is called
//Define alternateColor
function alternateColor(){
if(count == maxAlternations){ //Has the number of alternations been reached?
clearTimeout(timerId) //Cancel the threaded process and get the hell out of this function
}else{
window.status = document.bgColor //Set the current background color of the document on the status bar
/*
Is the current background color of the document black?
*/
if(document.bgColor == color1 || document.bgColor== "#000000"){
document.bgColor = color2 //Set the background color to white}else{ //The current background color is white
document.bgColor = color1 //Set the background color to black}
/*
Wait for 10th of a second (colorChangeDelay)
then call this function
and put the reference returned by setTimeout into timerId so it can be cleared
*/
timerId = setTimeout("alternateColor()",colorChangeDelay)
count ++ //Increment the count by one since the function was called
}
}
</script>
</head>
<!-- Make the onload event of the document call the alternateColor function -->
<body bgcolor="#FFFFFF" onLoad="alternateColor()" text="red">
<!-- Put the message in the middle of the document -->
<table height=100% width=100%>
<tr>
<td>
<h1><center>MICROSOFT IS THE KING<center></h1></td>
</tr>
</table>
</body>