我已经测试了以下生成和显示 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/