Random Rotating Banner Hack

It is working!
Press "F5" on your keyboard and a different banner should appear.
After two days of trying (yep very sad, but do I care!), I have finally modified my blogger template to do random roation on the banner graphics. If you don't get what I mean, press "F5" on your keyboard and a different banner should appear, if it happen to be the same banner then press again till you see a new one. It is a standard plug-in for Wordpress but we didn't have it in Blogger.... until now. Well I think this could be the first in the world of Blogger Beta, if not it is definitely my first hack anyway. Thanks Ramani from Hackosphere who gave me a few tips. Read on to see the scripts I have used.

I am not sure if it will works for all blogger templates, so I will just show you what I have done and you may have to modified it for your template. First of all I assume you have created a few graphical banners and have uploaded them onto a graphic hosting website.

For the 'Rounder' template I have used there is a piece of script in the CCS Style Section that read like this:


#header {
background:#476 url("http://www.blogblog.com/rounders4/bg_hdr_bot.jpg") no-repeat left bottom;
margin:0 0 0;
padding:0 0 8px;
color:#fff;
}


Basically my script works by overwriting the 'background' definition at the <body> part of the template. I wrote the following right after the <body> tag:




<script type="text/javascript">

var banner= new Array()

banner[0]="http://static.flickr.com/84/269053449_acad87a793_o.jpg"
banner[1]="http://static.flickr.com/95/269053438_4ef5a3983e_o.jpg"
banner[2]="http://static.flickr.com/96/269053404_44a3b0eda8_o.jpg"
banner[3]="http://static.flickr.com/108/269053262_608edbdda4_o.jpg"
banner[4]="http://static.flickr.com/98/269053232_6f7c6f994a_o.jpg"
var random=Math.round(4*Math.random());

document.write("<style>");
document.write("#header {");
document.write(' background:url("' + banner[random] + '") no-repeat left TOP;');
document.write(" }");
document.write("</style>");

</script>



My scripts above used Java Script to define an array of 5 url locations of the banners' graphic. Then the next line generate a random discret number between 0-4. The next part will generate some html codes to overwrite the "background" definition of the the "Header" style by selection a random banner everytime.

You will need to change the following:
1) The URL Locations of your graphics.
2) If you have 5 banners, you type "4" in the random number generating equation Math.round(4*Math.random()); If you have 3 banners type "2" and so forth.

Good luck, let me know if it works.



http://freeyasoul.blogspot.com/2006/10/random-rotating-banner-hack.html
Από το Blogger.

Get in Touch

Feel free to drop us a line to contact us

Name*


Message*


ΣΤΟΙΧΕΙΑ ΕΠΙΚΟΙΝΩΝΙΑΣ

Free time

  • https://www.freetimeradio.gr
  • https://www.9279.gr
  • bf@bf9279.com