Blog Banner

I banner e la pubblicità sul web

Creare una semplice rotazione banner in Javascript

lascia un commento »

Se volete inserire una semplice rotazione banner sulle vostre pagine, potete utilizzare il Javascript.
Il codice riportato di seguito visualizza banner Random, ossia, ad ogni caricamento della pagina viene visualizzato un banner diverso preso a caso tra quelli inseriti nel circuito:

<script language=”JavaScript”>
var banners = new Array();
banners[0] = new Banner(“
http://www.pippo.it”,”1.gif”);
banners[1] = new Banner(“http://www.clarabella.it”,”2.gif”);
banners[2] = new Banner(“http://www.paperone.it”,”3.gif”);
banners[3] = new Banner(“http://www.pluto.it”,”4.gif”);
banners[4] = new Banner(“http://www.paperino.it”,”5.gif”);

//…
//..
//banners[n] = new Banner(“
http://www.sito.it”,”n.gif”);

//banners[n+1] = new Banner(“http://www.altrosito.it”,”n+1.gif”);

function Banner(url,image) {
this.url = url;
this.image = image;
return this;
}
var id = Math.round(Math.random() * (banners.length – 1));

document.write(“<a href=\”" + banners[id].url + “\” target=\”_blank\”>”);
document.write(“<img src=\”" + banners[id].image + “\” border=\”0\”>”);
document.write(“</a>”);

</script>

Scritto da blogbanner

maggio 6, 2009 a 5:06 pm

Pubblicato in Le campagne banner

Lascia un Commento

Fill in your details below or click an icon to log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Log Out / Modifica )

Foto Twitter

You are commenting using your Twitter account. Log Out / Modifica )

Foto di Facebook

You are commenting using your Facebook account. Log Out / Modifica )

Connecting to %s

Follow

Get every new post delivered to your Inbox.