Horje
How to work a HTML Web Workers | HTML Web Workers API Code
How to work a HTML Web Workers

The example below creates a simple web worker that count numbers in the background:


Learn HTML Web Workers

Note: Internet Explorer 9 and earlier versions do not support Web Workers.

index.html
Example: HTML
<p>Count numbers: <output id="result"></output></p>
<button onclick="startWorker()">Start Worker</button> 
<button onclick="stopWorker()">Stop Worker</button>

<p><strong>Note:</strong> Internet Explorer 9 and earlier versions do not support Web Workers.</p>

<script>
var w;

function startWorker() {
  if(typeof(Worker) !== "undefined") {
    if(typeof(w) == "undefined") {
      w = new Worker("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>

Output should be:

Learn HTML Web Workers
Reffered: https://www.w3schools.com/html/html5_webworkers.asp



Read Full::
HTML Web Workers API Code
Category:
HTML Code
Sub Category:
HTML Web Workers API Code
Uploaded:
1 month ago
Uploaded by:
Admin
Views:
1

Related Articles
What is HTML Web Workers API HTML Web Workers API Code
What types of browsers will support HTML Web Workers API Code
How to work a HTML Web Workers HTML Web Workers API Code
How to check Web Worker Support HTML Web Workers API Code
How to create HTML Web Worker File HTML Web Workers API Code
How to Create a Web Worker Object HTML Web Workers API Code
How to Terminate a Web Worker HTML Web Workers API Code
How to Reuse the Web Worker HTML Web Workers API Code
Full Web Worker Example Code HTML Web Workers API Code
What is Web Workers and the DOM HTML Web Workers API Code

Single Articles
Learn HTML Web Workers

Share on: