0

Hi I'm trying to create a script which can stop every Javascript function. e.g

<button onclick='doSomething()'></button>

or

setInterval(doSomething, 200);

Is it possible to stop and disable those functions with another Javascript-File I mean get every interval like getElementByTanName(interval) and the a for function to clear them all

  • put the interval in a variable, and then clear it using `clearTimeout` – evolutionxbox Mar 28 '17 at 14:38
  • Possible duplicate of [setInterval and how to use clearInterval](http://stackoverflow.com/questions/5978519/setinterval-and-how-to-use-clearinterval) – evolutionxbox Mar 28 '17 at 14:39
  • 1
    Possible duplicate of [How to stop all timeouts and intervals using javascript?](http://stackoverflow.com/questions/3141064/how-to-stop-all-timeouts-and-intervals-using-javascript) – TimoStaudinger Mar 28 '17 at 14:41
  • @evolutionxbox do you know how to clear every interval without knowing the var name of them like getElementByTagName(intervals) – Steph Programm Mar 29 '17 at 10:29
  • There seem to be 3 possible questions here: 1) [how to remove all event handlers](http://stackoverflow.com/questions/4386300/javascript-dom-how-to-remove-all-events-of-a-dom-object) attached to the DOM; 2) how to stop all timeouts and intervals -- see previous comments; and 3) can you stop functions that have already been triggered by a timer or event handler? I think the answer to 3 is no. – Stuart Mar 29 '17 at 10:41
  • These answers cover stopping all JS execution: http://stackoverflow.com/questions/550574/how-to-terminate-the-script-in-javascript and http://stackoverflow.com/questions/9298839/is-it-possible-to-stop-javascript-execution – Stuart Mar 29 '17 at 10:48

1 Answers1

0

You need assing interval to variable, then you will be able to stop it using clearInterval function.

var interval = setInterval(function, 5000)
if(finished){
    clearInterval(interval);
}
cymruu
  • 2,808
  • 2
  • 11
  • 23