sumimakito / Awesome-qr.js

An awesome QR code generator written in JavaScript.
https://www.bitcat.cc/webapp/awesome-qr/index.html
Apache License 2.0
1.67k stars 251 forks source link

Javascript in browser error #50

Open b4oz opened 3 years ago

b4oz commented 3 years ago

Using the example set out in the READ.me gives me the following error in Chrome browser:

Uncaught TypeError: AwesomeQR is not a constructor at FileReader.reader.onload (jsqr.html:23)

What am I doing wrong?

I also had to add (dataURL) => '') instead of (dataURL) =>) to have the page load simply to test.

HTML Code is:

<script src="dist/awesome-qr.js"></script>
<body>
  <input type="file" onchange="previewFile()"><br>
  <img  src="" height="200" alt="Image preview...">
<script>

var background;

const preview = document.querySelector('img');
var reader = new FileReader();

reader.onload = function () {
  preview.src = this.result;
  background = this.result;

  new AwesomeQR({
    text: "AwesomeQR by Makito - Awesome, right now.",
    size: 500,
    backgroundImage: background,
  }).draw().then((dataURL) => );
};

function previewFile() {
  const file = document.querySelector('input[type=file]').files[0];

  if (file) {
    reader.readAsDataURL(file);
  }
}

</script>
</body>
ibnux commented 3 years ago

set constructor like this

new AwesomeQR.AwesomeQR({