Web Workers: Create a Web Worker Object

//the following lines checks if the worker already exists,
//if not - it creates a new web worker object and runs the code in
"demo_workers.js":

if (typeof(w) == "undefined") {
  w = new Worker("demo_workers.js");
}
//then we can send and receive messages from the web worker

//add an "onmessage" event listener to the web worker.

w.onmessage = function(event){
  document.getElementById("result").innerHTML = event.data;
};

Web Workers: Create a Web Worker Object — Structure map

Clickable & Draggable!

Web Workers: Create a Web Worker Object — Related pages: