Search code examples
javascriptphpqr-codebarcode-scanner

Barcode Scanner to redirect to url on scan


I have a USB barcode scanner that pastes data from the barcodes it scans. Is it possible to scan a barcode and redirect from the current browser and into a page based on the scanned information? This would be using php, html, and js


Solution

  • Something like this perhaps.

    <h3>Barcode</h3>
    <textarea class="bcode" name="barcode"></textarea>
    <span class="action"></span>
    

    Some js to handle the action

    $(function() {
      $('.bcode').on('paste',function(){
        var _this = this;
        setTimeout(function(){
          //now do something with the paste data
          window.location = "https://www.google.se/search?q=" + _this.value;
        },1000);
      });
    });
    

    Test the code here https://codepen.io/mbzbugsy/pen/EmZPYP