Jump to content

breaking an setTimeout


Intelly XAD

Recommended Posts

Hi, I was wondering if there is a possibility to stop or break an setTimeout
For example, when you have:

setTimeout('hello()', 5000);

hello() wil be executed in 5 seconds, but I was wondering if ik could be stopped when an other command is executed

Many thnx in Advance
Link to comment
https://forums.phpfreaks.com/topic/24330-breaking-an-settimeout/
Share on other sites

yes. first you will need do declare a varaiable before you set the time out. Here is a simple example.

[code=php:0]
//our timer variable
var timer;

function startTimer() {
    timer = setTimeout('hello();', 5000);
}

function stopTimer() {
    clearInterval(timer);
}
[/code]

Hope that helps,
Tom

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.