We have already seen the Worker code in the .js file. Below is the code for the HTML page: |
Example:
HTML
<!DOCTYPE html>
<html>
<body>
<p>Count numbers: <output id="result"></output></p>
<button onclick="startWorker()">Start Worker</button>
<button onclick="stopWorker()">Stop Worker</button>
<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! No Web Worker support.";
}
}
function stopWorker() {
w.terminate();
w = undefined;
}
</script>
</body>
</html>
What is HTML Web Workers API | HTML Web Workers API |
What types of browsers will support | HTML Web Workers API |
How to work a HTML Web Workers | HTML Web Workers API |
How to check Web Worker Support | HTML Web Workers API |
How to create HTML Web Worker File | HTML Web Workers API |
How to Create a Web Worker Object | HTML Web Workers API |
How to Terminate a Web Worker | HTML Web Workers API |
How to Reuse the Web Worker | HTML Web Workers API |
Full Web Worker Example Code | HTML Web Workers API |
What is Web Workers and the DOM | HTML Web Workers API |
Full Example Web Worker | HTML Web Workers API |
Read Full: | HTML Web Workers API |
Category: | Web Tutorial |
Sub Category: | HTML Web Workers API |
Uploaded: | 8 months ago |
Uploaded by: | Admin |
Views: | 4 |
Ref on: | View |