Iframe lien "src" aléatoire

Résolu/Fermé
Theophile76 Messages postés 1791 Date d'inscription mardi 6 mars 2007 Statut Membre Dernière intervention 16 avril 2021 - Modifié par Theophile76 le 18/03/2013 à 10:50
 seb - 20 mai 2013 à 22:11
Bonjour,
Donc voilà j'ai un 5 lien :
1 : http://www.site1.fr
2 : http://www.site2.fr
3 : http://www.site3.fr
4 : http://www.site4.fr
5 : http://www.site5.fr

Et j'ai un code iframe de ce style :
<iframe src="XXX"></iframe>

Et en fait je voudrais qu'à la place du XXX, j'ai de façon aléatoire l'un d'es 5 sites ci-dessus.
Sauriez-vous comment faire ?
Merci.



On s'ennuie pas avec l'informatique :)

2 réponses

Theophile76 Messages postés 1791 Date d'inscription mardi 6 mars 2007 Statut Membre Dernière intervention 16 avril 2021 372
18 mars 2013 à 14:35
Je viens de trouver un script qui marche bien, il faut juste remplacer les valeur à coté de "randomcontent" pas vos propre lien.

<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>

0
merci bien l'ami, ça faisait un petit moment que je chercher un script de ce genre en plus il marche nikel !!!
0