阅读W3C和Web Worker tutorial。我尝试创建一个Ember应用程序,该应用程序调用Web worker每秒在控制台中发送一条消息。但是,有些东西不起作用。您可以在行动in this jsbin中看到它。
if(typeof(Worker)!=="undefined") {
var blob = new Blob(["setInterval(function(){console.log('Hello');},1000);"]);
// Obtain a blob URL reference to our worker 'file'.
var blobURL = window.URL.createObjectURL(blob);
var worker = new Worker(blobURL);
worker.onmessage = function(e) {
console.log('inside onmessage');
// e.data == 'msg from worker'
};
worker.postMessage(); // Start the worker.
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support Web Workers...";
}