Back Action example


The index.html file containing JavaScript that makes use of the Back Action 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
<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Hardwarebuttons API usage example</title>
    <link rel="x-antenna-managed-webapp-descriptor" href="webapp-descriptor.xml" />
 
    <script type="text/javascript">
    var loaded = false;
    window.onLaunchboxLoaded = function () { //execute the setUp() function once the launchbox is ready
      loaded = true;
      setUp();
    }
    function setUp() {
      if(!loaded) {//check if launchbox is loaded
        alert("launchbox is not loaded yet");
        return;
      }
      window.launchbox.HardwareButtons.addListener({
        "onBackButtonPressed": function () {
          if (window.switch) {alert("SWITCH=TRUE");}
          else {
            alert("SWITCH=FALSE");
            window.launchbox.HardwareButtons.fireDefaultBackButtonAction();
          }
        }
      });
    }
    </script>
  </head>
  <body>
    <header>
      <h3><span>Hardware Buttons API Usage Example</span>
      </h3>
    </header>
    <div class="white_box_content" style="height: auto;">
      <div>
        <input type="button" onclick="javascript: window.switch = true;" value="switch=true
        - prevent default back action"/>
      </div>
      <div>
        <input type="button" onclick="javascript: window.switch = false;" value="switch=false
        - default back action" />
      </div>
    </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
9
CACHE MANIFEST
 
#v7
 
CACHE:
index.html
 
NETWORK:
*

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

1
2
3
4
5
6
7
<?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.hwbuttons</id>
    <version>1.0.0</version>
    <name>Back Action API usage example</name>
</webapp-descriptor>

Related topics

Public API reference
HardwareButtons
Legal notice | Copyright © 2015 and Confidential to Pegasystems Inc. All rights reserved. | Feedback
Advanced...