Click to See Complete Forum and Search --> : Random Image rotation script on RELOAD (with a twist)


leo_bassani
05-29-2003, 01:55 PM
Any ideas people???

I have the folowing task and I would really appreciate any hints.

The idea is to change 2 images on browser reload, simultaneously. They would randomly load, in sets of 2 that are linked together.


if you go to the test site at:

http://brickmill.com/webphase2/home.html

For example:

basically, upon page reload, the main picture and the BG TAG image would change to something else like this one for example

http://brickmill.com/webphase2/home2.html

So these sets of 2 images rotate on reload randomly, but the main picture and the BG are linked at all times. Again, on reload, the image home1.jpg would reload linked together with home_BG_1.jpg

Any ideas?????


I appreciate it!


thanks


Leonardo

Jona
05-29-2003, 04:26 PM
<html><head><title></title>
<script type="text/javascript">
<!--
var imgs = new Array("home1.jpg","home2.jpg");
var bgs = new Array("home_BG_1.jpg","home_BG_2.jpg");

function randBgImgs(){
var rand = Math.floor(2*Math.random());
var img = imgs[rand];
var bg = bgs[rand];
document.body.background.src=bg;
document.images["image_ID"].src=img;
}
//-->
</script></head><body onload="randBgImgs();">
<img src="" name="image_ID" alt="">
</body></html>


Jona

leo_bassani
06-02-2003, 09:59 AM
Hi on the following line:

document.images["image_ID"].src=img;

I removed the .src out of it, basically trial and error, and it worked "only" with style sheets below the java script.


Also, it did not in Netscape so a friend of mine gave me got some code for me check it out. Seems that modyfying background with javascript in a IE thing. It worked in Netscape when it was by itself, it does not wokr when part of the table structure. Strangeeee:

here is the code he came up with, and it works by itslf not inside the tables:

<html><head><title></title>

<script type="text/javascript">

<!--
var imgs = new Array("automate.jpg","falling_statue.JPG");
var bgs = new Array("automate.jpg","Clear_Day_Bkgrd.JPG");

var rand = Math.floor(2*Math.random());
var img = imgs[rand];
var bg = bgs[rand];

//-->

</script>

</head>


<!--<body onload="randBgImgs();"> -->
<script>
document.write('<BODY BACKGROUND="' + bg + '">');
document.write('<img src=' + img + ' name=image_ID>');
</script>


</body></html>

Jona
06-02-2003, 10:05 AM
It looks like it should work to me, regardless of whether or not it is in tables.

Jona