QR Code Scanner for Website

The barcode and QRcode have modernized our shopping and searching experience.Both barcode and QR code store information about an item or product in a machine-readable format that can be easily scanned with a barcode scanner or smartphones.QR code is more useful than a standard barcode.



Live Preview:




QR(Quick Response)code are little black and white squiggly barcodes.QR codes are usually read with laser scanners or camera on mobiles,which then use special software to decode the pattern.Many large companies and websites use this technique to attract the customers to them.You can help the users of your website to scan the QR code without any specific app. You don’t need any phone app to scan QR code.It’s very simple to create a QR code reader by yourself.It needs only some javascript code and a smartphone with camera.



CODE:




<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>

 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

 <script crossorigin="anonymous" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>


    <script src="https://rawgit.com/schmich/instascan-builds/master/instascan.min.js"></script>

     <video class="p-1 border" id="preview" style="width: 100%;"></video>



    <script type="text/javascript">

     var scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5, mirror: false });

     scanner.addListener('scan',function(content){

      alert(content);

      //window.location.href=content;

     });

     Instascan.Camera.getCameras().then(function (cameras){

      if(cameras.length>0){

       scanner.start(cameras[0]);

       $('[name="options"]').on('change',function(){

        if($(this).val()==1){

         if(cameras[0]!=""){

          scanner.start(cameras[0]);

         }else{

          alert('No Front camera found!');

         }

        }else if($(this).val()==2){

         if(cameras[1]!=""){

          scanner.start(cameras[1]);

         }else{

          alert('No Back camera found!');

         }

        }

       });

      }else{

       console.error('No cameras found.');

       alert('No cameras found.');

      }

     }).catch(function(e){

      console.error(e);

      alert(e);

     });

    </script>

    <br />
<div style="align-items: center; display: flex; justify-content: center;">
<label class="btn btn-primary active">

     <input autocomplete="off" checked="" name="options" type="radio" value="1" /> Front Camera

      </label>

      <label class="btn btn-secondary">

     <input autocomplete="off" name="options" type="radio" value="2" /> Back Camera

      </label>

    </div>
</div>



Codepen Embed:

See the Pen Light weight QR Code Scanner by Jinoy Varghese (@cspsyco) on CodePen.

Comments

  1. Thanks for the code. God bless you! :)

    ReplyDelete
  2. This is the code I'm looking for my project. Thanks a lot, CSPSYCO!

    ReplyDelete

Post a Comment

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Introducing Cloudflare Pages ⚡