3
Contributors
4
Replies
12
Views
7 Years
Discussion Span
Last Post by Jayavardhan
1
<html>
<body onMouseover="document.bgcolor='black'">
<font>
.
.
.
</font>
</body>
</html>

It was working fine for me.

Votes + Comments
You solved my problem. Thanks.,
0

If you are creating a page and want to change the background on click you might just assign a click event to the window that would toggle the background color of the page.For example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
<head>
<style type=text/css>
html,body{
	height:100%;
	width:100%;
}
</style>
<!--<script src="../lib/jquery-1.3.2.js" type="text/javascript"></script>-->
<script type="text/javascript">
 function init(){
	document.body.onclick = function(){
		colorChange();
	}		
	function colorChange(){
		var colors = ["red","green","blue","orange","pink"];
		var index = Math.floor(Math.random() * 100) % 5;
		document.body.style.background = colors[index];
	}
}
window.onload = init;
</script>
</head>
<body>
<p>Click the page to change colors</p>
</body>
</html>

In IE it is important to set the height and width of the body and html to 100% or IE thinks the body is just around the content and not the size of the screen. In FF it doesn't matter.

Edited by scrappedcola: n/a

0

Ur code was ok. But the poster was asking not to create a page. Just apply color when click on the page. As per his post, i suggest this code.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.