在手机网站的QR Code阅读器中打开后置摄像头

时间:2018-07-24 08:06:47

标签: android iphone qr-code webcam.js

您好从sitepoint获得了以下代码:

    <!DOCTYPE HTML>
<html>
    <head>
        <style>
            body, input {font-size:14pt}
input, label {vertical-align:middle}
.qrcode-text {padding-right:1.7em; margin-right:0}
.qrcode-text-btn {display:inline-block; background:url(//dab1nmslvvntp.cloudfront.net/wp-content/uploads/2017/07/1499401426qr_icon.svg) 50% 50% no-repeat; height:1em; width:1.7em; margin-left:-1.7em; cursor:pointer}
.qrcode-text-btn > input[type=file] {position:absolute; overflow:hidden; width:1px; height:1px; opacity:0}
        </style>
    </head>
    <body>
        <input type=text size=16 placeholder="Tracking Code" class=qrcode-text>
        <label class=qrcode-text-btn><input type=file accept="image/*" capture=environment onclick="return showQRIntro();" onchange="openQRCamera(this);" tabindex=-1></label> 
        <input type=button value="Go" disabled>
        <script src="qr_packed.js"></script>
        <script>
            function openQRCamera(node) {
              var reader = new FileReader();
              reader.onload = function() {
                node.value = "";
                qrcode.callback = function(res) {
                  if(res instanceof Error) {
                    alert("No QR code found. Please make sure the QR code is within the camera's frame and try again.");
                  } else {
                    node.parentNode.previousElementSibling.value = res;
                  }
                };
                qrcode.decode(reader.result);
              };
              reader.readAsDataURL(node.files[0]);
            }

            function showQRIntro() {
              return confirm("Use your camera to take a picture of a QR code.");
            }
        </script>
    </body>
</html>

在此代码中,单击QR图标将打开移动摄像头。但是我想在网页的指定区域中的页面上打开相机。我的屏幕设计如下: enter image description here

我的要求如下:

  • 默认情况下,PC /笔记本电脑中的移动摄像头或网络摄像头应打开并开始扫描。扫描后,代码应显示在输入框中。
  • 点击打开QR图标文件后,上传QR图片后,代码将显示在输入框中
  • 或用户可以键入/复制粘贴在输入框中的二维码。

我修改了webqr.com后创建了一个代码,该代码在台式机/笔记本电脑和android设备上可以正常工作,但是在ios设备和macbook中相机无法打开。

因此,我搜索并找到了上面的代码,该代码可以在iPhone和iPad中打开相机。但是不知道如何达到我的上述要求。

0 个答案:

没有答案
相关问题