neocotic / qrious

Pure JavaScript library for QR code generation using canvas
https://neocotic.com/qrious
Other
1.55k stars 216 forks source link

QRious not found since upgrade Chrome to latest version #130

Open Luigius opened 3 years ago

Luigius commented 3 years ago

Hi, My code was working fine until I updated chrome, since then this code returns: new QRious ({ element: document.getElementById("qrcodecanvas"), level: 'H', padding: 0, size: 250, value: dataqr }); Uncaught ReferenceError: QRious is not defined

the element is defined before the script code like this

I also tried to use canvas instead of img

Any suggestion? Thanks Luigi

ROBERT-MCDOWELL commented 3 years ago

did you try to create the object on window.onload ?

ROBERT-MCDOWELL commented 3 years ago

window.addEventListener("load",function(){ const head = document.getElementsByTagName('head')[0]; const qriousScript = document.createElement('script'); if(typeof(qriousScript.onreadystatechange) != "undefined"){ qriousScript.onreadystatechange = function(){ if(this.readyState == 'complete'){ build_something(); } } }else{
qriousScript.onload = build_something(); } qriousScript.src = 'qrious.min.js'; qriousScript.type = 'text/javascript'; head.appendChild(qriousScript); } });

Luigius commented 3 years ago

Hi, I solved the problem redownloading the qrious.js from github (link from the doc page https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.js).

Now without changing a line works, but until the chrome update was working fine. Not sure what was the problem Thanks Luigi

ROBERT-MCDOWELL commented 3 years ago

better you use the code above, it's not good to create an aboject before the page is loaded anyhow. chrome often changes preloading instructiona that can do things faster or in different order. your issue obviuosly comes from the fact that the object is created before the element is created, even if it's loaded after. loading the js script file once loaded (for this case) is 100% sure that it will react the same for all browsers.