Yes, Joe is right, but it's easy to mess this up.
You *MUST* make the variable that holds the "handle" to the timeout *global* to the page. Too often, people just make it local to the function that holds the window.open() call and then it doesn't work.
Also, if a timeout is already active, setting a *new* timeout does *NOT* clear the prior one! So...
<script>
var changeImageTimeout = null;
function changeImage()
{
...
// you might not need this, but it's not a bad idea:
if ( changeImageTimeout != null ) clearTimeout(changeImageTimeout);
changeImageTimeout = setTimeout('changeImage()',1000);
}
function stopChangeImage()
{
// don't call clear if it's not set...
if ( changeImageTimeout != null ) clearTimeout(changeImageTimeout);
changeImageTimeout = null; // tell yourself nothing is active
}
</script>
|