The index.html
file containing JavaScript that makes use of the
Network Status API functionality is listed below.
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 | <!DOCTYPE html> <html manifest= "manifest.appcache" > <head> <title>Network status example</title> <link rel= "stylesheet" href= "../css/style.css" type= "text/css" media= "all" /> <script type= "text/javascript" > function printText(str) { var d = document.getElementById( "results" ); d.appendChild(document.createTextNode(str)); d.appendChild(document.createElement( 'br' )); d.scrollTop = d.scrollHeight; }; var networkListener = function (type) { printText( "network type: " + type); }; function getNetwork() { printText(launchbox.Container.networkStatus.type); }; function addNetworkListener() { launchbox.Container.networkStatus.addListener(networkListener); }; function removeNetworkListener() { launchbox.Container.networkStatus.removeListener(networkListener); }; function clearOutput() { var d = document.getElementById( "results" ); d.innerHTML = "" ; }; </script> </head> <body> <header> <h3><span>Network Status API usage example</span> </h3> </header> <input type= "button" onclick= "getNetwork();" value= "getNetwork" /> <input type= "button" onclick= "addNetworkListener();" value= "addNetworkListener" /> <input type= "button" onclick= "removeNetworkListener();" value= "removeNetworkListener" /> <hr /> <input type= "button" onclick= "clearOutput();" value= "Clear output" /> <hr /> <div id= "results" > </div> </body> </html> |
The contents of the cache manifest file called manifest.appcache
for
this application are listed below:
1 2 3 4 5 6 7 8 | CACHE MANIFEST CACHE: NETWORK: * # NetworkStatus 1.0 |