Home >Web Front-end >JS Tutorial >How Can I Stop a JavaScript `setInterval` Call?
Stopping setInterval Calls in JavaScript
In JavaScript, setInterval(fname, 10000) can be utilized to trigger a function every 10 seconds. However, is it feasible to terminate this repetition based on a specific occurrence? This is particularly relevant when the constant data refresh needs to be halted at the user's discretion.
Solution
setInterval() returns an interval ID, which can be used with clearInterval():
var refreshIntervalId = setInterval(fname, 10000); /* later */ clearInterval(refreshIntervalId);
For further details, refer to the documentation for setInterval() and clearInterval().
The above is the detailed content of How Can I Stop a JavaScript `setInterval` Call?. For more information, please follow other related articles on the PHP Chinese website!