← Desenvolvimento

Javascript para rotação de banners

Lida 14319 vezes

Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Código: [Seleccione]
<SCRIPT LANGUAGE="JavaScript">


<!-- BANNER ROTATOR

var how_many_ads = 3
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;


//**************************** AD NUMBER ONE ****************

if (ad==1){


url="http://www.youradvertiser.com";

alt="Advertiser Number One";

banner="http://www.yourdomain.com/images/banner1.gif";

width="468";
height="60";
}

//**************************** AD NUMBER TWO ****************


if (ad==2) {


url="http://www.youradvertiser.com";

alt="Advertiser Number Two";

banner="http://www.yourdomain.com/images/banner2.gif";

width="468";
height="60";
}


//**************************** AD NUMBER ONE ****************

if (ad==3) {


url="http://www.youradvertiser.com";

alt="Advertiser Number Three";

banner="http://www.yourdomain.com/images/banner3.gif";

width="468";
height="60";
}


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



Depois altere como quiser!

var how_many_ads = 3 - aqui define quantos banners tem a rotação

Depois altera:

url="http://www.youradvertiser.com"; com a url do seu sponsor

alt="Advertiser Number One"; - com o texto que corresponderá ao banner e que aperecerá caso a imagem não esteja lá

banner="http://www.yourdomain.com/images/banner1.gif"; com a url de seu banner.

Espero ter ajudado!   :D
Offline

Tartaruga 
Membro
Mensagens 2908 Gostos 1
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

é possível fazer um script desse tipo, mas cada imagem (não necessáriamente um banner) acompanhado de um texto, e que muda a cada vez que o utilizador actualiza o site?

E já agora um script com o mesmo efeito mas só com texto?

Um exemplo mais concreto daquilo que estou a dizer pode ver-se em www.sapo.pt logo por baixo do motor de busca!

Um abraço!
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Citação de: "Tartaruga"
é possível fazer um script desse tipo, mas cada imagem (não necessáriamente um banner) acompanhado de um texto, e que muda a cada vez que o utilizador actualiza o site?

E já agora um script com o mesmo efeito mas só com texto?

Um exemplo mais concreto daquilo que estou a dizer pode ver-se em www.sapo.pt logo por baixo do motor de busca!

Um abraço!


É perfeitamente possível ;)

Diz-me uma coisa: o texto tem a ver com o banner ou tb ele é totalmente randomizado? Neste último caso complica um poucomais as coisas.
Offline

Tartaruga 
Membro
Mensagens 2908 Gostos 1
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

O texto teria a ver com a imagem (ou banner) ....

É desta maneira que é mais complicado?

Eu tou a precisar dos dois...

Um banner com texto (relacionado c o banner) que mudam a cada actualização da página.

E de um texto só, que também actualiza a cada vez que a pagina é actualizada.

Eu sei que não é muito complicado... mas n tenho conhecimentos que me permitam fazer isto...

Há e já agora também deve haver algum script que actualiza a página de x em x minutos né?

Um abraço
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Tenta lá isto:

Código: [Seleccione]

<script language="JavaScript">
<!--



function random_content(){
var mycontent=new Array()

mycontent[1]='<div style="text-align: center;"><a href="http://www.radarweb.net/adweb/clique.php?1104966670"><img alt="Apaixonante.com" src="http://img95.exs.cx/img95/8084/apaixonante336ag.gif" style="border: 0px solid ; width: 468px; height: 60px;"></a><br> </div> <div style="text-align: center;"><a target="_blank" href="http://www.radarweb.net/adweb/clique.php?1104966670">Apaixonante.com - atraia 75% mais mulheres</a><br> </div>'
mycontent[2]='<div style="text-align: center;"><a href="http://banners.spacash.com/bannerclick.php?account=tartaruga&n=ae8dfbf7&r=1149&t=1"><img alt="Acção interracial!" src="http://banners.spacash.com/bannerview.php?account=tartaruga&r=1149&t=1&n=ae8dfbf7" style="border: 0px solid ; width: 468px; height: 60px;"></a><br></div><div style="text-align: center;"><a target="_blank" href="http://banners.spacash.com/bannerclick.php?account=tartaruga&n=ae8dfbf7&r=1149&t=1">Acção interracial</a><br></div>'
mycontent[3]='<div style="text-align: center;"><a href="http://www.radarweb.net/adweb/clique.php?1104966670"><img alt="Apaixonante.com" src="http://img95.exs.cx/img95/8084/apaixonante336ag.gif" style="border: 0px solid ; width: 468px; height: 60px;"></a><br> </div> <div style="text-align: center;"><a target="_blank" href="http://www.radarweb.net/adweb/clique.php?1104966670">Apaixonante.com - atraia 75% mais mulheres</a><br> </div>'
mycontent[4]='<div style="text-align: center;"><a href="http://banners.spacash.com/bannerclick.php?account=tartaruga&n=ae8dfbf7&r=1149&t=1"><img alt="Acção interracial!" src="http://banners.spacash.com/bannerview.php?account=tartaruga&r=1149&t=1&n=ae8dfbf7" style="border: 0px solid ; width: 468px; height: 60px;"></a><br></div><div style="text-align: center;"><a target="_blank" href="http://banners.spacash.com/bannerclick.php?account=tartaruga&n=ae8dfbf7&r=1149&t=1">Acção interracial</a><br></div>'
mycontent[5]='<div style="text-align: center;"><a href="http://www.radarweb.net/adweb/clique.php?1104966670"><img alt="Apaixonante.com" src="http://img95.exs.cx/img95/8084/apaixonante336ag.gif" style="border: 0px solid ; width: 468px; height: 60px;"></a><br> </div> <div style="text-align: center;"><a target="_blank" href="http://www.radarweb.net/adweb/clique.php?1104966670">Apaixonante.com - atraia 75% mais mulheres</a><br> </div></b>'


var ry=Math.floor(Math.random()*mycontent.length)
if (ry==0)
ry=1
document.write(mycontent[ry])
}
random_content()
//-->
</script>


a seguir a "mycontent
  • =" podes colocar tudo aquilo que te apetecer randomizar (desde que seja entre'')
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Se achares mais fácil podes criar várias páginas htm com os teus anúncios e randomizar iframes com o seguinte script:

 
Código: [Seleccione]
<script language="JavaScript1.2">

//Random iframe content- © Dynamic Drive (www.dynamicdrive.com)
//For full source code, and Terms Of use, visit http://dynamicdrive.com
//This credit MUST stay intact for use

var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

//Specify IFRAME display attributes
var iframeprops='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'

//Specify random URLs to display inside iframe
var randomcontent=new Array()
randomcontent[0]="random1.htm"
randomcontent[1]="random2.htm"
randomcontent[2]="random3.htm"
randomcontent[3]="random4.htm"

//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')

function random_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
}
}

window.onload=random_iframe

</script>


Não te esqueças é de alterar:

Código: [Seleccione]
var iframeprops='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'


 8)
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Para fazeres o refresh da página x em x segundos:

Coloca entre as tags <head></head> o seguinte script:

Código: [Seleccione]
<script>
<!--



//tempo em segundos para o refesh:
var limit="0:30"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutos e "+cursec+" segundos até ao próximo refresh!"
else
curtime=cursec+" segundos para o próximo refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->
</script>


Este script tem uma coisa engraçada, no ie mostra na status o tempo que falta até ao próximo refresh ;)
Offline

Tartaruga 
Membro
Mensagens 2908 Gostos 1
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Obrigadão era mesmo isto que eu estava à procura...

Um abraço
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Citação de: "Tartaruga"
Obrigadão era mesmo isto que eu estava à procura...

Um abraço


Ainda bem que ajudou ;)
Offline

BL4CKIC3 
Membro
Mensagens 3439 Gostos 0
Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3

Bem o erro que da no meu site por causa desta rotação de banners, deve ser por causa do programa tonto que usava na construção de sites...Não é verdade fpware  :wink: ...lol...
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Citação de: "BL4CKIC3"
Bem o erro que da no meu site por causa desta rotação de banners, deve ser por causa do programa tonto que usava na construção de sites...Não é verdade fpware  :wink: ...lol...


 :lol:  :lol:  :lol:

Não tenho a menor dúvida acerca disso  ;)
Offline

Tartaruga 
Membro
Mensagens 2908 Gostos 1
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Citação de: "BL4CKIC3"
Bem o erro que da no meu site por causa desta rotação de banners, deve ser por causa do programa tonto que usava na construção de sites...Não é verdade fpware  :wink: ...lol...


Só para a gente se rir um bocadinho... qual era o programa?? ;)
Offline

fpware 
Fundador
Mensagens 15318 Gostos 7
Troféus totais: 38
Trófeus: (Ver todos)
Linux User Mobile User Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5

Não queiras saber...  :lol:  :lol:  :lol:
Offline

Tartaruga 
Membro
Mensagens 2908 Gostos 1
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

lololol Era mais grave que o meu frontpage?
Offline

BL4CKIC3 
Membro
Mensagens 3439 Gostos 0
Troféus totais: 32
Trófeus: (Ver todos)
Level 6 Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3

Muito mais grave !

Era o Publisher  :wink: