...

View Full Version : Javascript and IE problem.



ovcrash
05-19-2009, 12:39 AM
Hi,

I have this code :



<html>
<head>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
// Script de Fenetre vers l'exterieur
gSlideshowInterval = 30; // En seconde
gNumberOfImages = 4; // Nombre d'image dans le array

gImages = new Array(gNumberOfImages);
gImages[0] = "http://www.pixelweb.net/image.jpg";
gImages[1] = "http://216.137.100.129:81/IMAGE.JPG";
gImages[2] = "http://webcam.northco.net/montreal/montreal1.jpg";
gImages[3] = "http://webcam.northco.net/montreal/montreal2.jpg";

// Valide si le browser prend en charge les fonctions
function canManipulateImages() {
if (document.images)
return true;
else
return false;
}

// Load les images de l'array
function loadSlide(imageURL) {
if (gImageCapableBrowser) {
tmp = new Date();
tmp = "?" + tmp.getTime();
document.slide.src = imageURL + tmp;
return false;
}
else {
return true;
}
}

// Change l'image dans le slide
function nextSlide() {
gCurrentImage = (gCurrentImage + 1) % gNumberOfImages;
loadSlide(gImages[gCurrentImage]);
setInterval("loadSlide(gImages[gCurrentImage])", 5000); // Fait l'update de l'image en cours au 5 secondes
}

gImageCapableBrowser = canManipulateImages();
gCurrentImage = 0;
setInterval("nextSlide()",gSlideshowInterval * 1000); // Change l'image du slide au temp indiquer dans gSlideshowInterval
// -->
</SCRIPT>
</head>

<body>

<IMG SRC="http://webcam.northco.net/montreal/montreal1.jpg" NAME="slide" width="373" height="324">

</body>
</html>


But after a certain time, it makes IE crash.
Can anyone input with some solution...

Old Pedant
05-19-2009, 12:49 AM
I don't think you understand what that code is doing.

This line:
setInterval("nextSlide()",gSlideshowInterval * 1000);
says "every 30 seconds, call the nextSlide( ) function"

It does this by setting up an Interval object.
So, indeed, every 30 seonds nextSlide is called.

But then the nextSlide function has THIS line:
setInterval("loadSlide(gImages[gCurrentImage])", 5000);
which says "call the nextSlide function every 5 seconds"

AND EACH TIME YOU CALL loadSlide, you set up *ANOTHER* INTERVAL OBJECT!!!

So not surprisingly eventually you run out of memory, when enough of these interval objects have been created!!!

I think you MEANT to use setTimeout( ) and incorrectly used setInterval( )

setTimeout only happens one time and then disappears. setInterval happens for ever!

ovcrash
05-19-2009, 03:14 AM
Thanks for the answer.

But what i want to do, is show a picture for 120 secondes, then when that pictures is showed i want to update that image every 15 secondes, then at 120sec change the picture then update that picture every 15 secondes... and so on..

So is there anyway way to do this?
If i set a setTimeout, and it only happen once then my loop won't continue.. on and on.. ??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum