settimeout() in IE

Discussion in 'Javascript' started by Danijel, Mar 14, 2006.

  1. Danijel

    Danijel Guest

    Can anyone help me. When I try to run next code I get message: Stack
    overflow at line: 0. This only happens in IE while it works fine in Firefox.

    <HTML>
    <HEAD>
    <TITLE>setTimeout example</TITLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var dimages=new Array();
    var numImages=2;
    for (i=0; i<numImages; i++)
    {
    dimages=new Image();
    dimages.src="images/image"+(i+1)+".jpg";
    }
    var curImage=-1;

    function swapPicture()
    {
    if (document.images)
    {
    var nextImage=curImage+1;
    if (nextImage>=numImages)
    nextImage=0;
    if (dimages[nextImage] && dimages[nextImage].complete)
    {
    var target=0;
    if (document.images.myImage)
    target=document.images.myImage;
    if (document.all && document.getElementById("myImage"))
    target=document.getElementById("myImage");
    if (target)
    {
    target.src=dimages[nextImage].src;
    curImage=nextImage;
    }
    setTimeout("swapPicture()", 5000);
    }
    else
    {
    setTimeout("swapPicture()", 500);
    }
    }
    }
    setTimeout("swapPicture()", 5000);
    //-->
    </SCRIPT>
    </HEAD>
    <BODY>
    <img src="images/image2.jpg" onLoad="swapPicture()" name="myImage">
    </BODY>
    </HTML>
     
    Danijel, Mar 14, 2006
    #1
    1. Advertising

  2. Danijel

    VK Guest

    Danijel wrote:
    > Can anyone help me. When I try to run next code I get message: Stack
    > overflow at line: 0. This only happens in IE while it works fine in Firefox.
    >
    > <HTML>
    > <HEAD>
    > <TITLE>setTimeout example</TITLE>
    > <SCRIPT LANGUAGE="JavaScript">
    > <!--
    > var dimages=new Array();
    > var numImages=2;
    > for (i=0; i<numImages; i++)
    > {
    > dimages=new Image();
    > dimages.src="images/image"+(i+1)+".jpg";
    > }
    > var curImage=-1;
    >
    > function swapPicture()
    > {
    > if (document.images)
    > {
    > var nextImage=curImage+1;
    > if (nextImage>=numImages)
    > nextImage=0;
    > if (dimages[nextImage] && dimages[nextImage].complete)
    > {
    > var target=0;
    > if (document.images.myImage)
    > target=document.images.myImage;
    > if (document.all && document.getElementById("myImage"))
    > target=document.getElementById("myImage");
    > if (target)
    > {
    > target.src=dimages[nextImage].src;
    > curImage=nextImage;
    > }
    > setTimeout("swapPicture()", 5000);
    > }
    > else
    > {
    > setTimeout("swapPicture()", 500);
    > }
    > }
    > }
    > setTimeout("swapPicture()", 5000);
    > //-->
    > </SCRIPT>
    > </HEAD>
    > <BODY>
    > <img src="images/image2.jpg" onLoad="swapPicture()" name="myImage">
    > </BODY>
    > </HTML>


    Is your picture an animated gif ? (just checking)
     
    VK, Mar 14, 2006
    #2
    1. Advertising

  3. Danijel

    Danijel Guest

    > Is your picture an animated gif ? (just checking)

    No it's normal *.jpg picture.
     
    Danijel, Mar 14, 2006
    #3
  4. Danijel wrote:

    > Can anyone help me. When I try to run next code I get message: Stack
    > overflow at line: 0. This only happens in IE while it works fine in
    > Firefox.
    >
    > [...]


    Your markup is not Valid, and follows nonsensical notions of hiding scripts.

    > if (dimages[nextImage] && dimages[nextImage].complete)


    dimages[nextImage].complete is unreliable. For example,

    new Image().complete

    evaluates to `true' in Firefox 1.5.0.1.

    Do not use setTimeout() here, use the 'onload' event handler instead.
    (It fires when the image was loaded.)

    See also <URL:http://pointedears.de/scripts/test/hoverMe/>, which script
    code you can use, free of charge (but donations are always welcome), if you
    adhere to the terms of the GNU General Public License, version 2 or above
    as described in the comment. An even more sophisticated version, that will
    also be available as a library resource, is currently under construction.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Mar 15, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Pickering

    Smart navigation and js setTimeout

    Andy Pickering, Oct 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    504
    Andy Pickering
    Oct 27, 2003
  2. j van c

    settimeout

    j van c, Dec 5, 2003, in forum: HTML
    Replies:
    5
    Views:
    495
    Nico Schuyt
    Dec 7, 2003
  3. JR

    setTimeout

    JR, Apr 15, 2004, in forum: HTML
    Replies:
    3
    Views:
    546
    Whitecrest
    Apr 15, 2004
  4. =?Utf-8?B?RQ==?=

    javascript setTimeout does not work

    =?Utf-8?B?RQ==?=, May 2, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    8,837
    =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
    May 2, 2006
  5. Colin Brown

    socket settimeout ?

    Colin Brown, Dec 3, 2003, in forum: Python
    Replies:
    0
    Views:
    620
    Colin Brown
    Dec 3, 2003
Loading...

Share This Page