MikeHouston.net

Honorary member of the Shaolin

Scanning Barcodes with mobile device

About as easy as it comes thanks to Cordova and the BarcodeScanner Plugin.  ***Note** The following snippet assumes jQuery…obviously replace the $-# syntax if needed.

     <input type="button" onClick ="scanBarcode()" value ="Scan" />
    <hr/>
    <ul id="scans"></ul>

  <script type="text/javascript">
  function scanBarcode()
  {
    window.plugins.barcodeScanner.scan( function(result)
    {
       
        $('#scans').append('<li>' +
                      "Result: " + result.text + "<br/>" +
                      "Format: " + result.format + "<br/>" +
                      "Cancelled: " + result.cancelled +
                       "</li>");
                }, function(error)
                    {
                        alert("Scanning failed: " + error);
                    }
            );
  }
  </script>

Comments are closed