BarcodeScanner example


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

<!DOCTYPE html>
<html manifest="manifest.appcache">
  <head>
    <title>Barcode Scanner API usage example</title>
    <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 scanBarcode() {
      var barcodeScanner = window.launchbox.BarcodeScanner;
      barcodeScanner.scan({
        // One of the scan mode constants.
        'scanMode': window.launchbox.BarcodeScanner.SCAN_MODE_QR_CODE,

        // Specifies the character encoding to use when decoding
        // barcode data. Not supported by iOS.
        'characterSet': window.launchbox.BarcodeScanner.ENCODING_UTF_8, 

        'cropArea': {
          width: 550,
          height: 550
        }
      },
      {
        'onSuccess': function (result) {
          printText("Barcode scanner: success!");
          printText("Barcode data: " + result.data);
          printText("Barcode format: " + result.format);
        },
        'onCancel': function () {
          printText("Barcode scanner: cancel!");
        },
        'onFailure': function (error) {
          printText("Barcode scanner: error! " + error.description);
        }
      });
    }
    </script>
  </head>
  <body>
    <header>
      <h3><span>Barcode Scanner API usage example</span>
      </h3>
    </header>
    <input type="button" onclick="scanBarcode();" value="Scan Barcode"/>
    <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
BarcodeScanner
Legal notice | Copyright © 2018 and Confidential to Pegasystems Inc. All rights reserved
PDN | Feedback
Advanced...