Link to home
Start Free TrialLog in
Avatar of ml1n4
ml1n4Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Random images on page load - Both Javascript & html required...

Hello, this is a question that's been asked many times before but in fragments due to people usually knowing how to get started...  Can we assume NO knowledge on my part as to how to do this? Okay, here goes:

How do I get images to display randomly on a page each time it reloads?
i.e. A page banner that is different each time it is visited.  (I don't want the image to change whilst actually on screen).

I know I need a combination of Javascript and HTML but that's all I know.  Could somebody supply all the necessary code and end this question forever?

Many thanks indeed.
Avatar of sushestvo
sushestvo

<html>
 <body bgcolor="#EDEDED" text="#000000" link="#000000">
 <center>

<Script Language ="JavaScript">
 function RandomNumber()
 {
   var today = new Date();
   var num= Math.abs(Math.sin(today.getTime()/1000));
   return num;
 }
  function RandomGraphics()
 {
   var x = RandomNumber();
    if (x > .77)
 {document.write("<A HREF='http://www.womir.com/'><img src='004.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .66)
 {document.write("<A HREF='http://www.womir.com/'><img src='005.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .55)
 {document.write("<A HREF='http://www.womir.com/'><img src='006.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .44)
 {document.write("<A HREF='http://www.womir.com/'><img src='007.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .33)
 {document.write("<A HREF='http://www.womir.com/'><img src='008.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .22)
 {document.write("<A HREF='http://www.womir.com/'><img src='005.jpg' align=center hspace=10></a>"); return;
 }
   if (x > .11)
 {document.write("<A HREF='http://www.womir.com/'><img src='004.jpg' align=center hspace=10></a>"); return;
 }
   if (x > 0)  
 {document.write("<A HREF='http://www.womir.com/'><img src='008.jpg' align=center hspace=10></a>"); return;
 }
 }
 
 RandomGraphics();
 </SCRIPT>
<b>Reload page.</b>
 </body>
 </html>
ASKER CERTIFIED SOLUTION
Avatar of koolie
koolie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One other note about the link I posted, if you want to learn off of it it is very well documented