Quagga javascript barcode scanner - Uncaught TypeError: Quagga.init is not a function
Quagga javascript barcode scanner - Uncaught TypeError: Quagga.init is not a function
我正在尝试编写一些原始 javascript 代码来从我的网站进行条形码扫描,但是我什至无法通过使用 Quagga javascript library 的第一步。我的代码目前是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quagga Test</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=no" />
<script src="https://code.jquery.com/jquery-1.9.0.min.js" integrity="sha256-f6DVw/U4x2+HjgEqw5BZf67Kq/5vudRZuRkljnbF344=" crossorigin="anonymous"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/quagga/1.0.0-beta.1/quagga.js"></script>
</head>
<body>
<div id="interactive" class="viewport">
<video autoplay="true" preload="auto"></video>
</div>
<script type="text/javascript">
Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream",
target: document.querySelector('#interactive'),
constraints: {
width: 520,
height: 400,
facingMode: "environment" //"environment" for back camera, "user" front camera
}
},
decoder : {
readers : ["code_39_reader"]
}
}, function(err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
Quagga.onDetected(function(result) {
console.log(result.codeResult.code);
});
});
</script>
</body>
</html>
这给了我错误:
Uncaught TypeError: Quagga.init is not a function
有谁知道我需要做什么才能使 Quagga 网站的初始步骤在原版中运行 Javascript?
不确定是否与此有关:
const Quagga = require('quagga').default; // Common JS (important: default)
但这给出了错误:
Uncaught ReferenceError: require is not defined
结果我不得不改用 https://cdnjs.cloudflare.com/ajax/libs/quagga/0.12.1/quagga.min.js
。
我正在尝试编写一些原始 javascript 代码来从我的网站进行条形码扫描,但是我什至无法通过使用 Quagga javascript library 的第一步。我的代码目前是这样的:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Quagga Test</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; user-scalable=no" />
<script src="https://code.jquery.com/jquery-1.9.0.min.js" integrity="sha256-f6DVw/U4x2+HjgEqw5BZf67Kq/5vudRZuRkljnbF344=" crossorigin="anonymous"></script>
<script src="https://webrtc.github.io/adapter/adapter-latest.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/quagga/1.0.0-beta.1/quagga.js"></script>
</head>
<body>
<div id="interactive" class="viewport">
<video autoplay="true" preload="auto"></video>
</div>
<script type="text/javascript">
Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream",
target: document.querySelector('#interactive'),
constraints: {
width: 520,
height: 400,
facingMode: "environment" //"environment" for back camera, "user" front camera
}
},
decoder : {
readers : ["code_39_reader"]
}
}, function(err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
Quagga.onDetected(function(result) {
console.log(result.codeResult.code);
});
});
</script>
</body>
</html>
这给了我错误:
Uncaught TypeError: Quagga.init is not a function
有谁知道我需要做什么才能使 Quagga 网站的初始步骤在原版中运行 Javascript?
不确定是否与此有关:
const Quagga = require('quagga').default; // Common JS (important: default)
但这给出了错误:
Uncaught ReferenceError: require is not defined
结果我不得不改用 https://cdnjs.cloudflare.com/ajax/libs/quagga/0.12.1/quagga.min.js
。