工作线程中的 window.alert
如果我在 webworker 客户端上放置 window.alert,那么后台工作人员就会停止工作。 为什么会这样呢?
IE 调用者:
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");
}
If I put a window.alert on a webworker client, then the background worker stops working.
Why is this so?
i.e.
The caller:
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");
The client (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否注意到警报会冻结 JavaScript 引擎,直到用户单击“确定”。
如果您不想让它冻结,请不要使用警报。
对于使用 firebug 进行调试:
对于非锁定弹出窗口:
制作一个隐藏的 div,上面有一个 ok 按钮。当要显示弹出窗口时。让 div 可见。当用户单击“确定”时将其隐藏。
我建议你不要使用弹出窗口。它还打破了屏幕后面用户的“工作流程”(意味着用户的注意力):)
Has you have noticed the alert freezes the javascript engine until the user clicks OK.
If you don't want it to freeze don't use alerts.
For debuging with firebug:
For non locking popups:
make a hidden div with an ok button on it. When the popup is to be shown. Put the div visible. When the user clicks the "ok" hide it.
I would advise you not to use popups. It also breaks the "work flow" (meaning the concentration of the user) of the user behind the screen :)
Web Worker 是否有权访问 window.alert...我知道 Web Workers 无法访问 dom ..
在 Worker 中,为什么不做一个
does the web worker have access to window.alert...i know web workers do not get dom access..
in the worker, why not do a
Web Workers 允许您在后台运行 JavaScript 代码。 Web Worker 无法调用alert() 或confirm() 函数。
Web Workers Allow You to Run JavaScript Code in the Background. Web workers can't call alert() or confirm() functions.