The HTML DOM model is constructed as a tree of Objects:
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
The HTML DOM Document Object
The document object represents your web page.
A web worker is a JavaScript running in the background, without affecting the performance of the page.
<!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>
let w;
function startWorker() {
if (typeof w == "undefined") {
w = new Worker("demo_workers.js");
}
w.onmessage = function (event) {
document.getElementById("result").innerHTML = event.data;
};
}
function stopWorker() {
w.terminate();
w = undefined;
}
</script>
</body>
</html>
Since web workers are in external files, they do not have access to the following JavaScript objects:
- The window object
- The document object
- The parent object