I'm displaying a set of images as an overlay using googlemaps. Displaying these images should be in an endless-loop. Most most browsers detect this, and display a warning. Is there a way to make a endless-loop in javascript that is'nt stopped by the browser?
An endless loop? You are displaying an infinite number of images?
Try setInterval or setTimeout
EDIT: Like in this simple example: http://n0p.com/so/63011.php
Perhaps try using a timer which retrieves the next image each time it ticks, unfortunately i don't know any JavaScript so I can't provide a code sample
You should use a timer to continuously bring new images instead of an infinite loop. Check the setTimeout() function. The caveat is that you should call it in a function that calls itself, for it to wait again. Example taken from w3schools
<html>
<head>
<script type="text/javascript">
var c=0
var t
function timedCount()
{
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}
</script>
</head>
<body>
<form>
<input type="button" value="Start count!"
onClick="timedCount()">
<input type="text" id="txt">
</form>
</body>
</html>
Instead of using an infinite loop, make a timer that keeps firing every n seconds - you'll get the 'run forever' aspect without the browser hang.
function foo() { alert('hi'); setTimeout(foo, 5000); }
Then just use an action like "onload" to kick off 'foo'
The following code will set an interval and set the image to the next image from an array of image sources every second.
function setImage(){
var Static = arguments.callee;
Static.currentImage = (Static.currentImage || 0);
var elm = document.getElementById("imageContainer");
elm.src = imageArray[Static.currentImage++];
}
imageInterval = setInterval(setImage, 1000);
If it fits your case, you can keep loading new images to respond to user interaction, like this website does (just scroll down).
Just a formal answer:
var i = 0;
while (i < 1) {
do something...
if (i < 1) i = 0;
else i = fooling_function(i); // must return 0
}
I think no browser would detect such things.
Thevs, browsers will prompt you if any operation is taking too long. Your loop is not an exclusion. The only way is to use setInterval/setTimeout (as it has been already noted).