Button Rotation

Main >> Content >> Tutorials >> HTML >> Button Rotation

Have you ever been to a website which has this 'advertisment' thingy in the corner, and each time you visit the page, the button in the advertisment is different. There is actually a code for this thing and it is called 'Button rotation'.
Step 1: Start by copy the code under and paste it on to the page you want to have the button rotation on.
<style type="text/css">
</style><script language="javascript">

<!-- Begin
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
if (ad==1) {
url="WEBSITEURL";
alt="Alt Text";
banner="BUTTONURL";
width="88";
height="34";
}
if (ad==2) {
url="WEBSITEURL";
alt="Alt Text";
banner="BUTTONURL";
width="88";
height="34";
}
if (ad==3) {
url="WEBSITEURL";
alt="Alt Text";
banner="BUTTONURL";
width="88";
height="34";
}
if (ad==4) {
url="WEBSITEURL";
alt="Alt Text";
banner="BUTTONURL";
width="88";
height="34";
}

document.write('<a href=\"' + url + '\" target=\"_blank\">');
document.write('<img src=\"' + banner + '\" width=')
document.write(width + ' height=' + height + ' ');
document.write('alt=\"' + alt + '\" border=0></a>');
// End -->
</script>

Step 2: Okey, where it says BUTTONURL you have to paste the URL adress of the link buttons. Then you can paste in the website URL you want the button to link to where it says WEBSITEURL. You can also change the hight and width if you have to, so the link button fits:)

Step 3: In the code over you have 4 places to add buttons and web adresses. If you want more, you can just copy one of the 4 'codes' and type in 5 where it says if (ad==4) {.

Step 4: Under you can see an example of how the code works, each time you come to this page you'll see a different button.