Horje
How to Create a Web Worker Object

Now that we have the web worker file, we need to call it from an HTML page.

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


if (typeof(w) == "undefined") { w = new Worker("script.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;
}; 





Category :
Web Tutorial
Sub Category :
HTML Web Workers API
Uploaded by :
Admin


Read Article
https://horje.com/learn/1434/reference