Web Browser example


The index.html file containing JavaScript that makes use of the Web Browser 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Browser API sample usage</title>
    <link rel="stylesheet" href="../css/style.css" type="text/css" media="all" />
 
    <script type="text/javascript">
 
    function printText(str) {
      var d = document.getElementById('text-box');
      d.appendChild(document.createTextNode(str));
      d.appendChild(document.createElement('br'));
      d.scrollTop = d.scrollHeight;
    }
 
    function addL() {
      printText("Browser Listener Added");
      var callback = {
        onLoadFinished: function (url) {
          printText("Finished loading "+url);
        },
        onLoadStarted: function (url) {
          printText("Started loading "+url);
        },
        onClosed: function (url) {
          printText("Closed  "+url);
        },
        onLoadFailure: function (url, error) {
          printText("Failure loading "+url +"/n Error: "+error.description);
        }
      };
      launchbox.Browser.addListener(callback);
    }
 
    function openPage() {
      var external;
        var page_choice = document.getElementsByName('page_choice');
          for ( var i = 0; i < page_choice.length; i++) {
            if(page_choice[i].checked) {
              external = page_choice[i].value;
              break;
            }
          }
 
      window.launchbox.Browser.start("http://websitetips.com/articles/copy/lorem/ipsum.txt", {'external':Boolean(external)});
    }
 
    function clearOutput(){
      var d = document.getElementById('text-box');        
      d.innerHTML = "";
    }
 
    </script>
  </head>
 
  <body>
    <header>
      <h3><span>Browser API test</span>
      </h3>
    </header>
    <input type="button" onclick="addL();" value="Register a listener"/>
 
    <input type="button" onclick="openPage();" value="Open test page"/>
 
    <p>Internal <input type="radio" name="page_choice" value="" checked="checked"/></p>
 
    <p>External (in browser)<input type="radio" name="page_choice" value="1"/></p>
 
    <input type="button" onclick="clearOutput();" value="clear"/>
    <div id="text-box"></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
CACHE MANIFEST
 
CACHE:
index.html
 
NETWORK:
*

Related topics

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