Set background color randomly

Written by @kerixa 24 February 2014

This code sets the background color of the page randomly every 5 minutes.

Code Snippet:

                                                
                                                <!-- this script is provided by www.htmlbestcodes.com coded by: Kerixa Inc. -->
<!-- this script got from www.htmlbestcodes.com-Coded by: Krishna Eydat -->
<html>
<head>
<script type="text/javascript">
     //
      // Description: Randomly change background color every 5 seconds
      //
      // NewcWare 1997
      // Author: Scott Newcomer 3/1997
      // Email: nuke@bright.net
      //
      function setbackground()
      {
      window.setTimeout( "setbackground()", 5000); // 5000 milliseconds delay
      
      var index = Math.round(Math.random() * 9);
      
      var ColorValue = "FFFFFF"; // default color - white (index = 0)
      
      if(index == 1)
      ColorValue = "FFCCCC"; //peach
      if(index == 2)
      ColorValue = "CCAFFF"; //violet
      if(index == 3)
      ColorValue = "A6BEFF"; //lt blue
      if(index == 4)
      ColorValue = "99FFFF"; //cyan
      if(index == 5)
      ColorValue = "D5CCBB"; //tan
      if(index == 6)
      ColorValue = "99FF99"; //lt green
      if(index == 7)
      ColorValue = "FFFF99"; //lt yellow
      if(index == 8)
      ColorValue = "FFCC99"; //lt orange
      if(index == 9)
      ColorValue = "CCCCCC"; //lt grey
      
      document.getElementsByTagName("body")[0].style.backgroundColor = "#" + ColorValue;
      
      }
</script>
</head>
<body onload="setbackground();">
<br/><br/><div style="clear:both"></div><div><a target="_blank" href="http://www.htmlbestcodes.com/"><span style="font-size: 8pt; text-decoration: none">HTML Best Codes</span></a></div>
</body>
</html><a target='_blank' href='www.htmlbestcodes.com' style='font-size: 8pt; text-decoration: none'>Html Best Codes</a>                                                
                                            

Example:


About @kerixa

I am Krishna Eydat. I studied Software Engineering at University of Waterloo in Canada. I lead a few tech companies. I am passionate about the way we are connected. I would like to be part of something big or be the big deal!

K
TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: Nikhil 999+, bishalthakur
advertisement 2