Well, let's say I have a script of this type:

<script src="http://script.com/file.js"></script> 

I need it to work, for example, 3 seconds. How to put a temporary limit?

  • You have to put a restriction in the script itself, in html, as far as I know, there is no such thing. - mix
  • Any script can not be run for a certain time. But you can limit the time cycles in the script, for example. It all depends on the script code. - Mik
  • Tell us why it is needed - Oceinic
  • Well, actually, this script sends requests to various sites, I need to limit its work by time - Filipp Mustang

2 answers 2

Use WebWorker.

For example, on the Regex Golf website, the time for checking regular expression regularity is thus limited.

    We SetTimeout and in it we change global variable. And in the loop we track the change in the global variable.

    But so wrong. JavaScript does not work that way (you need to look towards asynchrony, events , etc.)

    • Um .. Why write with the answer that does not work? - Qwertiy
    • Will work. We set a variable change on SetTimeout, and in our long-running script we constantly check the value of the variable. Only this is ugly. - Vlad Chapl
    • Will not be. Or give an example. - Qwertiy