Log in

View Full Version : Random linked banners (one by one) at each refresh/reload



Wisdom
08-25-2010, 08:12 AM
Does anyone know such a script ? I searched but I din't find what I was looking for :(

And I don't want to complicate things with hosted files. I want to use this for advertisement on my site.

Thanks !

jscheuer1
08-25-2010, 08:45 AM
http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm

http://www.dynamicdrive.com/dynamicindex14/swissarmy/index.htm

Either of the two above slide show scripts can do linked images. And they can each also be set up in manual mode without controls or descriptions. And they each also have an optional random setting. So it's just a matter of which one you like. As I say, either can be set to show just one image w/link per page load.

Wisdom
08-29-2010, 08:29 PM
Hi,

Thank you for your reply, the code is good, but is there another, one wich I can use directly html codes


<a href="" title=""><img src="" /></a>

Even javascript. Is there ?

Wisdom
09-01-2010, 10:47 AM
Sorry for the bump but can anyone help me please ?

lilpete
09-01-2010, 12:37 PM
Hi,
I do not know of a script whereby you can have all the html on the page and it just chooses one of them to display, I use this one here: www.test.steptoes.co.uk (http://www.test.steptoes.co.uk) to display different adverts on the left hand side.

Thats all you need in your body tags..

<script type="text/javascript" src="js/banner.js"></script>

Thats all you need in the external file.. (js/banner.js)

<!--
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="images/banner/1.jpg"
myimages[2]="images/banner/2.jpg"
myimages[3]="images/banner/3.jpg"
myimages[4]="images/banner/4.jpg"
myimages[5]="images/banner/5.jpg"
myimages[6]="images/banner/6.jpg"

//specify corresponding links below
var imagelinks=new Array()
imagelinks[1]="/link1.html"
imagelinks[2]="/link2.html"
imagelinks[3]="/link3.html"
imagelinks[4]="/link4.html"
imagelinks[5]="/link5.html"
imagelinks[6]="/link6.html"
var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}
random_imglink()
//-->

I think that is pretty easy to use. You can see the HTML the script will write out in the javascript.
Hope that helps.

jscheuer1
09-01-2010, 04:39 PM
You could combine the two -

banner.js:


function random_imglink(){
var myimages = [], ry, lnk;
//specify random images below. You can have as many as you wish
myimages[0] = "images/banner/1.jpg";
myimages[1] = "images/banner/2.jpg";
myimages[2] = "images/banner/3.jpg";
myimages[3] = "images/banner/4.jpg";
myimages[4] = "images/banner/5.jpg";
myimages[5] = "images/banner/6.jpg";

//specify corresponding links below
var imagelinks = [];
imagelinks[0] = "/link1.html";
imagelinks[1] = "/link2.html";
imagelinks[2] = "/link3.html";
imagelinks[3] = "/link4.html";
imagelinks[4] = "/link5.html";
imagelinks[5] = "/link6.html";

ry = Math.floor(Math.random() * myimages.length);
lnk = document.getElementById('bannerlink');
lnk.href = imagelinks[ry];
lnk.getElementsByTagName('img')[0].src = myimages[ry];
}
random_imglink();

In the body section where you want the banner to appear:


<a id="bannerlink" href="/link1.html" title=""><img src="images/banner/1.jpg" alt="" /></a>
<script type="text/javascript" src="js/banner.js"></script>

Wisdom
09-02-2010, 11:54 AM
Thank you !