Vraagje van scriptnoob.
Ik gebruik een script om na klik op een beginplaatje een random plaatje te openen op de pagina. Nou wil ik door op dat geopende plaatje te klikken weer terug gaan naar het eerste plaatje.
Een mogelijkheid zou zijn om het plaatje een link te geven naar de beginpagina, maar hoe plaats je een link in een array?
Script wat ik gebruik staat hieronder, pagina waar ik het wil plaatsen is www.ingridtenboske.nl
<!-- THREE STEPS TO INSTALL RANDOM CLICK IMAGE:
1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Nicholas Lupien (smylex@aol.com) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "image1.gif";
images[2] = new Image();
images[2].src = "image2.gif";
images[3] = new Image();
images[3].src = "image3.gif";
images[4] = new Image();
images[4].src = "image4.gif";
images[5] = new Image();
images[5].src = "image5.gif";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY OnLoad="swapPic()">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<center>
<a onClick="swapPic();"><img name="randimg" src="image1.gif"></a><br>
<font face="Verdana" size="-2">click image to change</font>
</center>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.49 KB -->
Ik gebruik een script om na klik op een beginplaatje een random plaatje te openen op de pagina. Nou wil ik door op dat geopende plaatje te klikken weer terug gaan naar het eerste plaatje.
Een mogelijkheid zou zijn om het plaatje een link te geven naar de beginpagina, maar hoe plaats je een link in een array?
Script wat ik gebruik staat hieronder, pagina waar ik het wil plaatsen is www.ingridtenboske.nl
<!-- THREE STEPS TO INSTALL RANDOM CLICK IMAGE:
1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Nicholas Lupien (smylex@aol.com) -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
var rand1 = 0;
var useRand = 0;
images = new Array;
images[1] = new Image();
images[1].src = "image1.gif";
images[2] = new Image();
images[2].src = "image2.gif";
images[3] = new Image();
images[3].src = "image3.gif";
images[4] = new Image();
images[4].src = "image4.gif";
images[5] = new Image();
images[5].src = "image5.gif";
function swapPic() {
var imgnum = images.length - 1;
do {
var randnum = Math.random();
rand1 = Math.round((imgnum - 1) * randnum) + 1;
} while (rand1 == useRand);
useRand = rand1;
document.randimg.src = images[useRand].src;
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->
<BODY OnLoad="swapPic()">
<!-- STEP THREE: Copy this code into the BODY of your HTML document -->
<center>
<a onClick="swapPic();"><img name="randimg" src="image1.gif"></a><br>
<font face="Verdana" size="-2">click image to change</font>
</center>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
<!-- Script Size: 1.49 KB -->