Reputation: 309
I am using http://davidshimjs.github.io/qrcodejs/ to generate qr-code
var qrcode = new QRCode("qrcode", {
text: "http://jindo.dev.naver.com/collie",
width: 128,
height: 128,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
console.log(qrcode);
console.log(qrcode._el.children[1].currentSrc);
I can find the base64 code in "qrcode"
But why I get empty when I run:
console.log(qrcode._el.children[1].currentSrc);
Is there any other method to get the base64 code?
Upvotes: 1
Views: 5268
Reputation: 624
Try:
setTimeout(function () {
const base64String = document.querySelector("#qrcode img").src;
});
The reason for that is that it simply runs async and needs some time to be set to the image attribute.
Upvotes: 1