Tricky Tricks ›› Programming Tricks ›› Javascript Tricks ›› Random Image Plus Link

Random Image Plus Link

Javascript Tricks

Random Image Plus Link:

This very useful and adaptable script is great for using multiple images with multiple links. It can be used to change either by surfer (sufer1, surfer2, etc.), by days of the week or even on a monthly change-up basis. It's more than a banner changer...it's a great way to totally automate changes in your site!

<SCRIPT LANGUAGE="JavaScript"> <!-- // script written by Kurt A> // http://www.geocities.com/soho/lofts/1238 // This script selects an image dependant on the second the user // logs in. That image can have it's own link // good for banners to other pages. var dt = new Date(); var sec = dt.getSeconds();// if (sec<=20) means seconds 0 through 20// change the IMG SRC = and the msg.link location to your own needs. if (sec<=20) { var msg="<IMG SRC= gif/a.gif>"; document.write(msg.link("gif/a.gif")) ;}// else if (sec<=40) means seconds 21 through 40 else if (sec<=40) { var msg="<IMG SRC= gif/b.gif>"; document.write(msg.link("gif/b.gif")) ;}// else means all the rest of the seconds 41 through 60 else { var msg="<IMG SRC= gif/d.gif>"; document.write(msg.link("gif/d.gif")) ;}// the order of the if,else if, and else are important. The program reads from // the top down so if an if or else if work it will not read the following// else ifs or else. (else is a catch all). To add more you just add mores // else ifs and change the values. Say you wanted 6 images.// if (hr <=10) .......// else if (hr <=20)........// else if (so on until you reach 50)// else ......// it's also easily modified for minutes months years if you want a banner// to appear all day on a certain day then then another on another day.

<!-- end -->

</SCRIPT>


Partners