window.alert工作线程

window.alert工作线程

问题描述:

如果我把一个window.alert一个webworker客户端上,然后将背景工人停止工作。 这是为什么呢?window.alert工作线程

即 来电者:

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"); 
} 

有你已经注意到警报冻结JavaScript引擎,直到用户点击确定。

如果你不希望它冻结不使用警报。

对于萤火虫调试运行:

console.log("bla bla bla"); 

对于非锁定弹出窗口:

使与它确定]按钮的隐藏的股利。弹出窗口显示时。让div可见。当用户点击“确定”时隐藏它。

我劝你不要使用弹出窗口。这也打破了屏幕:)

+0

工作者线程不能使用的console.log – jas7 2013-11-19 22:54:41

+0

@控制台jas7专用工人(已经)使用,共享的工人不能。 – maja 2014-08-24 16:58:41

做的网络工作者有机会获得window.alert背后的用户的“工作流程”(意为用户的浓度)...我知道网络工作者没有得到访问DOM ..

在工人

,为什么不做一个

if (window && window.alert) { 
    // do your normal thing 
} 
else { 
    postMessage("no support for this"); 
} 
+0

Web工作人员不能调用alert()。 – 2018-02-09 00:48:43

的Web Workers允许你在后台运行JavaScript代码。 Web工作人员不能调用alert()或confirm()函数。