Forum Moderators: open
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
#container {
background-color: #fff;
}
</style>
<title>Untitled</title>
<script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript">
YAHOO.util.Event.on(window, 'load', function() {
function d2h(d) {return d.toString(16);}
// Generate a random background color
var rgb = '#' + d2h(Math.round(255*Math.random())) + '' +
d2h(Math.round(255*Math.random())) + '' +
d2h(Math.round(255*Math.random()));
YAHOO.util.Dom.setStyle(document.body, 'background-color', rgb);
alert('Set the background color to: ' + rgb);
});
</script>
</head>
<body>
<div id="container">
Here's my page
</div>
</body>
</html>
[edited by: Fotiman at 3:30 am (utc) on Jan. 12, 2008]
lavazza,
This is similar to what I need, but I need the background to be random, not just a spcific image.
Fotiman,
This is almost what I need, but I want it to ba an image, and not a color, not sure how to modify this to take file names, and not numbers.
Again, thanks for your input guys :)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<style type="text/css">
#container {
background-color: #fff;
}
</style>
<title>Untitled</title>
<script type="text/javascript" src="http://yui.yahooapis.com/2.4.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript">
YAHOO.util.Event.on(window, 'load', function() {
// Choose a random background image
var bgimgs = [
'image1.jpg',
'image2.jpg',
'image3.jpg'
];
var idx = Math.round(bgimgs.length * Math.random());
YAHOO.util.Dom.setStyle(document.body, 'background-image', bgimgs[idx]);
alert('Set the background image to: ' + bgimgs[idx]);
});
</script>
</head>
<body>
<div id="container">
Here's my page
</div>
</body>
</html>
[edited by: Fotiman at 5:47 pm (utc) on Jan. 15, 2008]