Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

image aleatoire avec fichier .js

1 réponse
Avatar
christophe
salut


Quelqu'un sais comment on peut faire qu'une image soit aléatoire chaque fois
que la page charge

Dans le site la université de Columbia aUSA http://www.columbia.edu/ ils
fait une appel a une fichier js.

Moi j'essaye a faire la même chose mais je ne pas réussi

Quelqu'un peut m'aide.

Si vous plait
voici mon code

Code dans le fichier ;js:


//IMAGE ROTATE SCRIPT
var imgArray = new Array();

//Place image names here:
imgArray[0] = "photo0.gif";
imgArray[1] = "photo1.gif";
imgArray[2] = "photo2.gif";
imgArray[3] = "photo3.gif";


var numImgs=imgArray.length;
var randNum = Math.floor(Math.random() * numImgs);





code page html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT language="JavaScript">
src="Images/imgRotate.js" </SCRIPT>
</head>
<body>
<table border="1" align="center" cellpadding="0" cellspacing="0"
bordercolor="#000000">
<tr>
<td width="204" height="323"> <SCRIPT language="JavaScript">
<!--
document.write('<img src="images/'+imgArray[randNum]+'"
width="204" height="323" alt="photo" title="photo" border="0">');
//-->
</SCRIPT>
</td>
</tr>
</table>
</body>
</html>


Merci beaucoup

Ciao

1 réponse

Avatar
O.L.
Chez moi ça marche (j'ai un peu modifié le script), essaie chez toi :

<script>

//IMAGE ROTATE SCRIPT
var imgArray = new Array();

//Place image names here:
imgArray[0] = "photo0.gif";
imgArray[1] = "photo1.gif";
imgArray[2] = "photo2.gif";
imgArray[3] = "photo3.gif";


var numImgs=imgArray.length;
var randNum = Math.floor(Math.random() * numImgs);

</script>

<html>
<body id=booody>
<table border="1" align="center" cellpadding="0" cellspacing="0"
bordercolor="#000000">
<tr>
<td width="204" height="323" idÝd>
<SCRIPT language="JavaScript">
document.write('<img src="images/'+imgArray[randNum]+'" width="204"
height="323" alt="photo" title="photo" border="0">');
</SCRIPT>
</td>
</tr>
</table>
</body>
</html>

Bye
O.L.






christophe a présenté l'énoncé suivant :
//IMAGE ROTATE SCRIPT
var imgArray = new Array();

//Place image names here:
imgArray[0] = "photo0.gif";
imgArray[1] = "photo1.gif";
imgArray[2] = "photo2.gif";
imgArray[3] = "photo3.gif";


var numImgs=imgArray.length;
var randNum = Math.floor(Math.random() * numImgs);





code page html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<SCRIPT language="JavaScript">
src="Images/imgRotate.js" </SCRIPT>
</head>
<body>
<table border="1" align="center" cellpadding="0" cellspacing="0"
bordercolor="#000000">
<tr>
<td width="204" height="323"> <SCRIPT language="JavaScript">
<!-- document.write('<img
src="images/'+imgArray[randNum]+'" width="204" height="323" alt="photo"
title="photo" border="0">');
//-->
</SCRIPT>
</td>
</tr>
</table>
</body>
</html>


--
Ceci est une signature automatique de MesNews.
Site : http://mesnews.no-ip.com