navigator-onLine.html (1026B)
1 <!doctype html> 2 <title>navigator.onLine in dedicated worker</title> 3 <pre>Log: 4 </pre> 5 <script> 6 var pre = document.querySelector('pre'); 7 var worker, shared; 8 try { worker = new Worker('navigator-onLine.js'); } catch(e) { pre.textContent += '\nnew Worker threw: ' + e.message; } 9 try { shared = new SharedWorker('#', ''); } catch(e) { pre.textContent += '\nnew SharedWorker threw: ' + e.message; } 10 if (worker) { 11 worker.onmessage = function(e) { 12 pre.textContent += '\ndedicated worker: ' + e.data; 13 } 14 } 15 if (shared) { 16 shared.port.onmessage = function(e) { 17 pre.textContent += '\nshared worker: ' + e.data; 18 } 19 } 20 function update() { 21 pre.textContent += '\n\n' + new Date() + '\n<script>: ' + navigator.onLine; 22 if (worker) worker.postMessage(1); 23 if (shared) shared.port.postMessage(1); 24 } 25 update(); 26 ononline = onoffline = update; 27 </script> 28 <p>As you go online and offline, the log should be filled with the correct status of navigator.onLine.</p> 29 <p><button onclick="update()">Check navigator.onLine status</button></p>