admin管理员组文章数量:1314246
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 putation
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 putation
done()
}
};
function done(){
alert('don'); // ===> This kills the worker.
// Send back the results to the parent page
postMessage("done");
}
Share
Improve this question
asked Apr 12, 2010 at 14:02
Lydon ChLydon Ch
8,81520 gold badges80 silver badges136 bronze badges
3 Answers
Reset to default 2Has 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:
console.log("bla bla bla");
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 :)
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
if (window && window.alert) {
// do your normal thing
}
else {
postMessage("no support for this");
}
Web Workers Allow You to Run JavaScript Code in the Background. Web workers can't call alert() or confirm() functions.
本文标签: javascriptwindowalert in worker threadStack Overflow
版权声明:本文标题:javascript - window.alert in worker thread - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741964787a2407483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论