settimeout() in IE

D

Danijel

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>
 
V

VK

Danijel said:
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)
 
T

Thomas 'PointedEars' Lahn

Danijel said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top