networkStatus example


The index.html file containing JavaScript that makes use of the Network Status API functionality is listed below.

<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Network status example</title>
	<link rel="x-antenna-managed-webapp-descriptor" href="webapp-descriptor.xml" />
    <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:

CACHE MANIFEST

CACHE:

NETWORK:
*

# NetworkStatus 1.0

The webapp-descriptor.xml file for this application is defined in the following way:

<?xml version="1.0" encoding="UTF-8"?>
<webapp-descriptor xmlns="http://www.pega.com/application-hosting/
web-app-descriptor/2.0">
  <id>com.pega.sample.NetworkStatus</id>
  <version>1.0</version>
  <name>Network Status API usage example</name>
</webapp-descriptor>

Related topics

Public API reference
networkStatus
Legal notice | Copyright © 2016 and Confidential to Pegasystems Inc. All rights reserved
PDN | Hybrid Container | Feedback
Advanced...