Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript and IE problem.

    Hi,

    I have this code :

    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...
    Last edited by Kor; 05-19-2009 at 01:30 PM. Reason: use [code] not [icode] for posting codes

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,151
    Thanks
    80
    Thanked 4,557 Times in 4,521 Posts
    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!

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.. ??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •