Container API example


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

<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Container API usage example</title>
    <script type="text/javascript">
      var loaded = false;
      window.onLaunchboxLoaded = function () {
        loaded = true;
        initListeners();
      }

      function initListeners(){
        if(!loaded) {
          alert("launchbox is not loaded yet");
          return;
        }
        launchbox.Container.addLifecycleListener({
          onShow: function() {
            printText("onShow callback");
          },
          onHide: function() {
            printText("onHide callback");
          },
          onPause: function() {
            printText("onPause callback");
          },
          onResume: function() {
            printText("onResume callback");
          }
        });
      }

      function getID(){
          printText(launchbox.Container.deviceId);
      }

      function printText(str) {
        var d = document.getElementById('text-box');
        d.appendChild(document.createTextNode(str));
        d.appendChild(document.createElement('br'));
        d.scrollTop = d.scrollHeight;
      }
      function clearOutput(){
        var d = document.getElementById('text-box');
        d.innerHTML = "";
      }

    </script>
  </head>
  <body>
    <header>
      <h3>Container API usage example</h3>
    </header>
    <div>
      <input type="button" onclick="getID();" value="Get device ID"/>
      <input type="button" onclick="clearOutput();" value="Clear output"/>
      <input type="button" onclick="closeApp();" value="Close an application"/>
    </div>
    <hr />

    <div id="text-box">
    </div>
  </body>
</html>

The contents of the cache manifest file called manifest.appcache for this application are listed below:

CACHE MANIFEST

CACHE:
index.html

NETWORK:
*

Related topics

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