2011-06-07, 08:38 AM
2011-06-07, 08:53 AM
Use this code where ever you want Random Banner with Link to appear
Original article and tip by alirex: http://yaldaram.com/showthread.php?tid=490
<script language="Javascript">
<!--
var currentdate = 0;
var core = 0;
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}
link = new initArray(
"http://www.linkofsite1.com",
"http://www.linkofsite2.com",
"http://www.linkofsite3.com"
);
image = new initArray(
"http://linkofbanner1.com",
"http://linkofbanner2.com",
"http://linkofbanner3.com"
);
text = new initArray(
"Name Of Site1",
"Name Of Site2",
"Name Of Site3"
);
var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];
document.write('<a href=\"' +ranlink+ '\" target=\"_blank\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');
//-->
</SCRIPT>
Original article and tip by alirex: http://yaldaram.com/showthread.php?tid=490
2011-06-07, 08:55 AM
thanks but i want show this banner on header banner only so should place above coding in index page
2011-06-07, 08:58 AM
You've to edit header template and replace the logo URL from there. Then paste the above code in place of that.
2011-06-07, 09:11 AM
that you placed the javascript in the header but its not working
2011-06-07, 09:14 AM
Did you changed the Image path in the following options ?
image = new initArray(
"http://linkofbanner1.com",
"http://linkofbanner2.com",
"http://linkofbanner3.com"
2011-06-07, 09:31 AM
Put this in your 'header' template where you would like to display the random banner:
It uses Prototype, which is already included in MyBB.
I just grabbed some Google Doodles with the appropriate links, but you can of course change them in whatever you want and add them as long as you use the same format as I used.
<div id="banner">
<a href="http://www.google.com/search?q=dragonboat">
<img src="http://www.google.com/logos/2011/dragonboat11-hp.jpg" />
</a>
</div>
<script type="text/javascript">
var banners = [
{
'url': "http://www.google.com/search?q=dragonboat",
'img': "http://www.google.com/logos/2011/dragonboat11-hp.jpg"
},
{
'url': "http://www.google.com/search?q=scarry",
'img': "http://www.google.com/logos/2011/scarry11-hp.png"
},
{
'url': "http://www.google.com/search?q=first+man+in+space",
'img': "http://www.google.com/logos/2011/firstmaninspace11-hp.jpg"
}
];
var randomBanner = banners[Math.floor(Math.random()*banners.length)];
$$('#banner a').invoke('writeAttribute','href',randomBanner.url);
$$('#banner img').invoke('writeAttribute','src',randomBanner.img);
</script>
It uses Prototype, which is already included in MyBB.
I just grabbed some Google Doodles with the appropriate links, but you can of course change them in whatever you want and add them as long as you use the same format as I used.