What is a Web Worker?
When you execute a script in an HTML page, the state of the page is not responsive until the script is complete.
Web Worker is a JavaScript running in the background, independent of other scripts, without affecting the performance of the page. You can continue to do anything you want to do: Click, select Content, and so on, while the Web worker runs in the background.
Detect if the browser supports Web Worker
Before you create a web worker, detect whether the user's browser supports it:
if (typeof (Worker)!== "undefined")
{
Yes! WEB Worker Support!
//
some code .....
}
Else
{
I'm sorry! Web Worker does not support
}
<! DOCTYPE html> <meta charset="Utf-8"> <title> Rookie Tutorial (runoob.com) </title> "result"></output></p><button onclick="Startworker ()"> Start work </button> <button onclick="Stopworker ()"> Stop Working </button><p><strong> note:</strong> Internet Explorer9And earlier versions of IE browsers do not support Web workers.</p><script>varw;function Startworker () {if(typeof(Worker)!=="undefined") { if(typeof(w) = ="undefined") {W=NewWorker ("Demo_workers.js"); } w.onmessage= function (Event) {document.getElementById ("result"). InnerHTML =Event. Data; }; } Else{document.getElementById ("result"). InnerHTML ="Sorry, your browser does not support Web Workers ..."; }}function Stopworker () {w.terminate (); W=undefined;}</script></body>Web Worker Case