如果我在 webworker 客户端上放置一个 window.alert,那么后台 worker 就会停止工作。 为什么会这样?
即 来电者:
var worker = new Worker("worker.js");
// Watch for messages from the worker
worker.onmessage = function(e){
// The message from the client:
e.data
};
worker.postMessage("start");
客户端(worker.js)
onmessage = function(e){
if ( e.data === "start" ) {
// Do some computation
done()
}
};
function done(){
alert('don'); // ===> This kills the worker.
// Send back the results to the parent page
postMessage("done");
}
最佳答案
web worker 是否有权访问 window.alert...我知道 web worker 没有 dom 访问权限..
在worker中,为什么不做一个
if (window && window.alert) {
// do your normal thing
}
else {
postMessage("no support for this");
}
关于javascript - 工作线程中的 window.alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2622598/