Skip to content Skip to sidebar Skip to footer

Qr Code To Dataurl

I am trying to generate a QR code using davidshimjs/qrcodejs with the code below. But, when i try to generate DataURL, it gives following error : TypeError: document.getElementByI

Solution 1:

That's because toDataURL only works on the <canvas> element.

canvas.toDataURL(type, encoderOptions);

See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL

UPDATE

Here is how you would get the data URL...

varQRId = "123456789"var qrcode = newQRCode("qrcode", {
    text: QRId,
    width: 200,
    height: 200,
    colorDark : "#000000",
    colorLight : "#ffffff",
    correctLevel : QRCode.CorrectLevel.H
});

// get the qr div, then find the canvas element inside itvar canvas = document.getElementById('qrcode').querySelector('canvas');

var dataURL = canvas.toDataURL();

document.getElementById('result').innerHTML = dataURL;
<scriptsrc="https://cdn.rawgit.com/davidshimjs/qrcodejs/master/qrcode.js"></script><divid="qrcode"></div><divid="result"></div>

Post a Comment for "Qr Code To Dataurl"