Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > settimeout() in IE

Reply
Thread Tools

settimeout() in IE

 
 
Danijel
Guest
Posts: n/a
 
      03-14-2006
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[i]=new Image();
dimages[i].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>


 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      03-14-2006

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[i]=new Image();
> dimages[i].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)

 
Reply With Quote
 
 
 
 
Danijel
Guest
Posts: n/a
 
      03-14-2006
> Is your picture an animated gif ? (just checking)

No it's normal *.jpg picture.


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      03-15-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments