1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <!DOCTYPE html> <html lang="zh-TW"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf8"> <style> div { border: solid 2px #336699; margin: 10px; padding: 5px; border-radius: 5px; -moz-border-radius: 5px; vertical-align: top; text-align: center; display: inline-block; } #panel { width: 400px; background: #AACCEE; text-align: left; font-size: 10pt; display: block; } #panel1 { width: 400px; background: #AACCEE; text-align: left; font-size: 10pt; display: block; } </style> </head> <body> <div>Web Worker Global Scope<div id="panel"></div></div> <div>Shared Worker Global Scope<div id="panel1"></div></div> </body> </html> <script> try { var worker = new Worker('test644.js'); worker.onmessage = function(e) { document.getElementById('panel').innerHTML += e.data; }; worker.postMessage('start'); } catch(e) { document.getElementById('panel').innerHTML += '<span style="color:red">No Worker support.</span>'; } try { var sharedworker = new SharedWorker('test644a.js','shared'); sharedworker.port.onmessage = function(e) { document.getElementById('panel1').innerHTML += e.data; } sharedworker.port.postMessage('start'); } catch(e) { document.getElementById('panel1').innerHTML += '<span style="color:red">No SharedWorker support.</span>'; } </script> |
Direct link: https://paste.plurk.com/show/325391