简体   繁体   English

扫描HTML5 / JavaScript中的条形码

[英]Scan Barcode in HTML5/JavaScript

I'm looking for a way to scan for a barcode and return a response based on whether it received the barcode or not. 我正在寻找一种扫描条形码的方法,并根据是否收到条形码返回响应。 The only results I can find point to the Intel XDK. 我能找到的唯一结果就是英特尔XDK。 I can't use that for this particular project, so it is possible to do it without it? 我不能将它用于这个特定的项目,所以没有它可以做到这一点吗? How do I scan for a barcode with HTML5/JavaScript? 如何使用HTML5 / JavaScript扫描条形码?

Here is the link I found originally , which looks like it could do the job if I was able to use the Intel XDK. 这是我最初找到的链接 ,如果我能够使用英特尔XDK,它看起来可以完成这项工作。 Let me know what I can add to this question to be more clear, I just need to be pointed in the right direction as I don't know where to begin or how to actually scan once I've accessed the camera. 让我知道我可以添加到这个问题更清楚,我只需指向正确的方向,因为我不知道从哪里开始或如何实际扫描一旦我访问相机。 Here's the code I'm using to access and show the device camera: 这是我用来访问和显示设备摄像头的代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="stuff, to, help, search, engines, not" name="keywords">
<meta content="What this page is about." name="description">
<meta content="Display Webcam Stream" name="title">
<title>Display Webcam Stream</title>

<style>
#container {
    margin: 0px auto;
    width: 500px;
    height: 375px;
    border: 10px #333 solid;
}
#videoElement {
    width: 500px;
    height: 375px;
    background-color: #666;
}
</style>
</head>

<body>
<div id="container">
    <video autoplay="true" id="videoElement" controls="true">

    </video>
</div>
<script>
var video = document.querySelector("#videoElement");

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;

if (navigator.getUserMedia) 
{       
    navigator.getUserMedia({video: true}, handleVideo, videoError);
}

function handleVideo(stream)
{
    video.src = window.URL.createObjectURL(stream);
}

function videoError(e) 
{
    alert("I don't understand. Why did you not allow it?");
}
</script>
</body>
</html>

Most of the time barcode scanners act like a keyboard - they "type" the result. 大多数时候条形码扫描仪就像键盘一样 - 它们“键入”结果。 You capture it by either listening to keypress events, or by listening to changes in an input field. 您可以通过监听按键事件或通过侦听输入字段中的更改来捕获它。

More information on the particular technology used to capture the barcode would be required to answer this question in more detail. 有关用于捕获条形码的特定技术的更多信息将需要更详细地回答该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM