Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the src #160

Open
digitalrnd opened this issue Apr 30, 2018 · 5 comments
Open

Getting the src #160

digitalrnd opened this issue Apr 30, 2018 · 5 comments

Comments

@digitalrnd
Copy link

I'm trying to grab the src of the image generated, however, it only works after the 2nd click.

$("#apply").click( function(){
    var src = qrcode._oDrawing._elImage.currentSrc;
    console.log(src);
});
@heinrichmartin
Copy link

I'm using the src from the DOM and it works - even for a download link that grabs its href on click.
$(this).attr("href", $("#qrcode img").attr("src"));
HTH
Martin
Disclaimer: not a maintainer, just a user.

@phamhuyvn
Copy link

i must wait img rendered before get scr

@phamhuyvn
Copy link

you can try. i still countinue test this
$("#text").on("blur", async () => {
const imgUrl = await qrcode.makeCode(document.getElementById("text").value);
console.log($('img').attr('src'));
});

@scammi
Copy link

scammi commented Nov 15, 2018

    new QRCode(qrdiv, links)
    setTimeout(makeLink, 1000)

    function makeLink(){
      var qrlink = document.getElementById("downloadLink")
      var imgsrc = document.getElementsByTagName("img")[0].src
      qrlink.href = imgsrc
      qrlink.innerHTML = "Click here to downloar your QRcode"
      console.log(imgsrc)
    }

I added the timeout, so the src from the qrcode has enough time to load in order to be copied. 

@lifengboy
Copy link

try this

const div = document.createElement('div');
new QRCode(div, "http://jindo.dev.naver.com/collie");
const src = div.children[0].toDataURL("image/png");
console.info('src', src);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants