博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

web worker 教程

Posted on 2012-07-24 00:27  bug yang  阅读(178)  评论(0编辑  收藏  举报

 

 

var worker = new SharedWorker('work.js'); 
worker.port.addEventListener('message', function(e) { 
    alert(e.data); 
}, false); 
worker.port.start(); 
worker.port.postMessage(msg);

 

 

var connect_number = 0; 
onconnect = function(e) { 
    connect_number =connect_number+ 1; 
    var port = e.ports[0]; 
    port.postMessage('The current connection number is ' 
                              + connect_number); 
    port.onmessage = function(e) { 
        port.postMessage('Request msg'); 
    }; 
};