Software Technology Tips

The following Javascript code will help you change the background-color of your web-page automatically and at a time-interval (in milli-seconds) as specified in the code.
<script type="text/javascript" language="javascript">
/* Method To Generate Random Numbers Between "0-255" for RGB Color-code Format & Assign To Body-Backgrond-Style */
function bgDisco()
var  x =Math.round(255*Math.random());

var num1 =getHex(x);

var  y =Math.round(255*Math.random());

var num2 =getHex(y);

var  z =Math.round(255*Math.random());

var num3 =getHex(z);"#"+num1+num2+num3;

/* Method To Convert  Decimal To Hexadecimal */

function getHex(dec)
var hexArray = new Array( "0", "1", "2", "3","4", "5", "6", "7","8", "9", "A", "B","C", "D", "E", "F" );
var code1 = Math.floor(dec / 16);
var code2 = dec - code1 * 16;
var decToHex = hexArray[code2];
return (decToHex);
Now on the body part call the "bgDisco()" in onload event.
<body onload="bgDisco()">

Related Tags:


Author: Soumya Panda


Let us Connect!

Awards and Achievements

Red Herringcolor DeloitteFast50 DB ZInnov1   Nascome  DB Stpi

This site uses cookies. We respect your privacy.copyright (c) Mindfire Solutions 2007-2015. Login