En fait comme je ne m'y connais pas beaucoup en javascrit je n'arrive pas è bien comprendre ce que je dois faire.
En fait j'ai essayé ceci mais ça ne marche pas comme je le veux (la redirection automatique ne se fait pas):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <SCRIPT LANGUAGE="JavaScript">
function go_to(url) {
window.location = rand_link(); //ou comme ça window.location = rand_link;
}
function rand_link() {
var a;
a = 1+Math.round(Math.random()*6); // a = random number between 1-3
if (a==1) go_to("1.php");
if (a==2) go_to("2.php");
if (a==3) go_to("3.php");
if (a==4) go_to("4.php");
if (a==5) go_to("5.php");
if (a==6) go_to("6.php");
}
// End -->
</SCRIPT> |
Et j'appele ma fonction comme ça
<a href=\"javascript:go_to(rand_link())\">
En fait voici le contenu complet de ma page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>
<link rel="stylesheet" href="css/style-main.css" type="text/css" media="all" />
<SCRIPT LANGUAGE="JavaScript">
function go_to(url) {
window.location=url;
}
function rand_link() {
var a;
a = 1+Math.round(Math.random()*6); // a = random number between 1-3
if (a==1) go_to("1.php");
if (a==2) go_to("2.php");
if (a==3) go_to("3.php");
if (a==4) go_to("4.php");
if (a==5) go_to("5.php");
if (a==6) go_to("6.php");
}
</SCRIPT>
</head>
<BODY onload=startLoading()>
<DIV ID="Main">
<SCRIPT>
var pics = new Array("images/aBox-buttons.gif",
"photos/logo/logo-1.jpg",
"photos/logo/logo-2.jpg",
"photos/logo/logo-3.jpg",
"photos/logo/logo-4.jpg",
"photos/logo/logo-5.jpg");
var url = "index2.php";
var doConfirm = false;
var canSkip = true;
var imgObjs = new Array(pics.length);
var loaded = 0;
var total = pics.length;
var cPercent = 0;
var barLayer = null;
var percentLayer = null;
var doneMsgLayer = null;
function getLayer(layerID) {
if (document.getElementById)
return document.getElementById(layerID);
else if (document.all)
return document.all[layerID];
else
return null;
}
function updateBar() {
var percent = Math.round(loaded/total * 100);
if (cPercent != percent)
{
cPercent = percent;
barLayer.style.width = (cPercent*3) +"px";
percentLayer.innerHTML = "<font color=\"#000000\"><B>" +cPercent+ "%</B></font>";
}
if (loaded == total)
{
doneMsgLayer.innerHTML = "<a href=\"javascript:rand_link()\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><B>Complété (Cliquer ici)</B></font></a>";
if (doConfirm && confirm("Téléchargement complété...Voulez vous continuer?"))
done();
}
}
function startLoading() {
if (document.getElementById || document.all)
{
barLayer = getLayer("bar");
percentLayer = getLayer("percent");
doneMsgLayer = getLayer("doneMsg");
if (canSkip)
doneMsgLayer.innerHTML = "<a href=\"javascript:rand_link()\"><font color=\"#000000\" size=\"2\" face=\"Arial\">Annulé le préchargement</font></a>";
for (i=0; i<pics.length; i++)
{
imgObjs[i] = new Image();
imgObjs[i].onload = imgLoaded;
imgObjs[i].onerror = imgFailed;
imgObjs[i].src = pics[i];
}
}
else
{
alert("You are likely running very old browser which is not compatible with preloading script. Maybe it is time to update your browser.\n\nProgram is skipping preloading.");
window.location.replace(url);
}
}
function done() {
parent.window.location.replace(url);
}
function imgFailed() {
alert("The following image failed to load, probably a broken link:\n" +this.src+ "\nPlease contact the webmaster of the site you are visiting about this. The program will skip this file now.");
loaded++;
updateBar();
}
function imgLoaded() {
loaded++;
updateBar();
}
</SCRIPT>
<DIV id=msg style="LEFT: 100px; WIDTH: 250px; POSITION: absolute; top: 285px; HEIGHT: 20px"><FONT
face=Arial color=#000000 size=4>Préchargement en cours...</FONT></DIV>
<DIV id=bg></DIV>
<DIV id=bar></DIV>
<DIV id=percent style="LEFT: 330px; POSITION: absolute; top: 285px;"><FONT color=#000000><B>0%</B></FONT>
</DIV>
<DIV id=doneMsg style="LEFT: 375px; POSITION: absolute; top: 285px;"></DIV>
</div>
</BODY>
</html> |
Peut-être pourriez vous me donner le code complet.
Merci
Frédéric
Partager