javascript - 在没有 HTML DOM 的情况下显示 JavaScript 生成的二维码

标签 javascript html

我已经测试了以下生成和显示 QR 码的方法,并且它在我的桌面上运行良好。

我使用的图书馆是qrcode.js

<head>
  <title>Cross-Browser QRCode generator for Javascript</title>
  <script type="text/javascript" src="qrcode.js"></script>
</head>

<body>
  <div id="qrcode" style="width:100px; height:100px; margin-top:15px;"></div>
  <script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
      width: 100,
      height: 100
    });

    qrcode.makeCode("Hello World");
  </script>
</body>

问题是我想在限制使用 JavaScript 的嵌入式设备上运行此代码:

...all JS code is preprocessed before executing the HTML code. Thus in JS one cannot get or read any of the html elements. This may limit the use third party JS library components which typically allow getting access to the HTML DOM element and then perform operations which is not allowed in our case.

是否可以在不使用 getElementById 的情况下在 HTML 中显示此 QR?

最佳答案

我猜这个库没有。这个库也需要一个 dom 元素来附加。

可能的解决方案是生成和 qr-image。然后打开图片? 另一种解决方案是将返回的 SVG 转换为 base64,然后打开 url。但这需要重写qrcode.js文件。

关于javascript - 在没有 HTML DOM 的情况下显示 JavaScript 生成的二维码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53046919/

相关文章:

html - Bootstrap 表响应式头部固定主体可滚动

JavaScript 切换大小写

javascript - 有没有办法阻止 sequelize sync() 添加特定的外键?

javascript从类名分配函数

javascript - 如何使用Jquery从动态表中获取值?

PHP Session 安全关键步骤

html - 如何使用像素而不是百分比使 div 在页面上水平拉伸(stretch)?

javascript - Google geochart 如何向右指针显示工具提示框

php - 如何动态更新div颜色everythime php函数在html页面中重新运行

html - TableView 在 Chrome 和 IE、Firefox 中显示不同