The Worker()
constructor creates a Worker
object that executes the script at the specified URL. This script must obey the same-origin policy.
Note: that there is a disagreement among browser manufacturers about whether a data URI is of the same origin or not. Though Gecko 10.0 (Firefox 10.0 / Thunderbird 10.0 / SeaMonkey 2.7) and later accept data URIs, that's not the case in all other browsers.
new Worker(aURL, options);
The following code snippet shows creation of a Worker
object using the Worker()
constructor and subsequent usage of the object:
var myWorker = new Worker('worker.js');
first.onchange = function() {
myWorker.postMessage([first.value,second.value]);
console.log('Message posted to worker');
}
For a full example, see our Basic dedicated worker example (run dedicated worker).
The Worker
interface it belongs to.