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