Created
June 16, 2023 11:28
-
-
Save MFathurrohmanMauludin/3db07c439b2654a9d044dc3aac58b8b6 to your computer and use it in GitHub Desktop.
QR Code Reader - Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>QR Code Reader using Javascript</h1> | |
<!-- QR SCANNER CODE BELOW --> | |
<div class="row"> | |
<div class="col"> | |
<div id="reader"></div> | |
</div> | |
<div class="col" style="padding: 30px"> | |
<h4>Scan Result </h4> | |
<div id="result"> | |
Result goes here | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When scan is successful fucntion will produce data | |
function onScanSuccess(qrCodeMessage) { | |
document.getElementById("result").innerHTML = | |
'<span class="result">' + qrCodeMessage + "</span>"; | |
} | |
// When scan is unsuccessful fucntion will produce error message | |
function onScanError(errorMessage) { | |
// Handle Scan Error | |
} | |
// Setting up Qr Scanner properties | |
var html5QrCodeScanner = new Html5QrcodeScanner("reader", { | |
fps: 10, | |
qrbox: 250 | |
}); | |
// in | |
html5QrCodeScanner.render(onScanSuccess, onScanError); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5-qrcode/2.2.0/html5-qrcode.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h1 { | |
text-align: center; | |
} | |
#reader { | |
width: 500px; | |
} | |
.result { | |
background-color: green; | |
color: #fff; | |
padding: 20px; | |
} | |
.row { | |
display: flex; | |
} | |
#reader__scan_region { | |
background: white; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment