The Java Scriptorium

Random Background Colour


Description

Generates random background colour. Sets the colour on page entry. Can optionally let visitor click link to generate new colour. Can also display new colour code. Be careful not to set bgcolor or background.

Example

Click here to get new background colour.
Background color

Code

In the <head> section of your document:

<!-- JavaScript -->
<script language="JavaScript">
<!-- Begin
function rnd(scale) {
	var dd=new Date();
	return((Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%scale)); }
function show() {
	document.blah.bg.value=document.bgColor;
}
document.bgColor=256*rnd(255)+16*rnd(255)+rnd(255);
// End -->
</script>

In the <body> section of your document:

<BODY ONLOAD="show()"> 

<a href="javascript:history.go(0)">Click here to get new background colour.</a> 
<!-- to let visitor generate new colour -->

<form name=blah>Background color <input type=text name=bg></form>
<!-- to display new colour value -->

Return to the Java Scriptorium.