injoy
injoy

Reputation: 4383

How to implement a background execution in JavaScript?

For example, I would like to download part of data from the server when I click one button, and downloading other parts in background. How to implement this?

Upvotes: 1

Views: 124

Answers (2)

Mehdi Karamosly
Mehdi Karamosly

Reputation: 5438

If you are targetting HTML5 compatible browsers take a look at Web Workers :

http://www.html5rocks.com/en/tutorials/workers/basics/

Background processes with web workers:

http://www.youtube.com/watch?v=VIdkYaLbzMs

Upvotes: 2

Uriel
Uriel

Reputation: 211

You have only one execution thread, so you will have to play with setInterval() and clearInterval() and execute your code based on timers :

var iv= setInterval(function(){ alert("Running now!"); }, 3000);

Clear the periodic function with :

clearInterval(iv);

Upvotes: 0

Related Questions