Monday, 15 March 2010

Can I put impose a time limit on JavaScript (e.g., using an iframe)? -


I would like to run some external javascript with a deadline, so that if it takes longer than n seconds it will stop.

Some browsers, like Firefox, already do this with a dialog that asks if you want to continue running the script. However, I'm looking for a bit more:

  • Instead of using the default of browser (like, I think Chrome has a lot of time compared to Firefox) Want to set your own time limit?
  • I want to be able to do this on a per-script basis, not per page. One page can have several scripts, which I want to restrict in this way (hence my idea of ​​using & lt; iframe & gt; elements).

    I was thinking that it can be very convenient if only one attribute happens then i and lt; Iframe & gt; , for example, js-time-limit = "5000" (I just made it up above) but I have not found anything like that.

    Is this possible? To set a configurable time frame on JavaScript execution in the browser?

    If the iframe calculation is working and does not need to reach the DOM, then the web workers Use:

    There is also a library that can remove the hard parts for you!

    Important parts:

    Dedicated web workers provide a simple tool for web content to run scripts in background threads.

    If you need to end the immediately running worker, you can do the termination of the worker by calling () method: myWorker.terminate ( ); Browser compatibility

      Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit) 3 3.5 (1.9 .1) 10 10.60 4    

No comments:

Post a Comment