Scan barcodes with Dynamsoft Barcode Scanner
by DynamsoftTeam
HTML
<!DOCTYPE html>
<html>
<head>
<title>Barcode Scanner</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.4.3000/dist/dbr.bundle.js"></script>
</head>
<body>
<p id="barcodeResults">Click to scan a barcode</p>
<button onclick="scan()">Scan</button>
<script>
async function scan() {
try {
// Use your 30-day free trial license if you already have one, or obtain one at: https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&package=js
// const result = await new Dynamsoft.BarcodeScanner({license:"YOUR_LICENSE_KEY_HERE"}).launch();
const result = await new Dynamsoft.BarcodeScanner().launch();
const text = result.barcodeResults?.[0]?.text || "No barcode found";
barcodeResults.textContent = "Result: " + text;
} catch (e) {
barcodeResults.textContent = "Error: " + e.message;
}
}
</script>
</body>
</html>