I want to create a QR Code Generator like this: QR Code Generator | CodingNepal. I have an idea of how to do it, but I’m having trouble figuring out the exact syntax since w-ebflow adds additional classes.
This is broken now as Google Charts no longer supports QR codes. Anyone have any new suggestions?
UPDATE:
Here’s a way to do this once and for all without needing a 3rd party service. You will need to host a QR code generating JS file somewhere. I use AWS S3 as I load several external JS files. The other main one being a light embedded YouTube handler/player. There’s probably some CDN that already has this file hosted or something similar that you can just link to.
Then on your webflow page’s settings in the Before </body> tag section, add/tweak the following example code:
<!--
Load minified QR code library from our AWS S3 libs bucket.
This goes at the end so we don't need to defer/async it. It can
block until loaded as we don't want the following code to run if
the library isn't loaded.
-->
<script type="text/javascript" src="<your_host>/js/qrcode_min.js"></script>
<script>
// This calls the qr code generator to generate the QR codes
const url = "<the_url_to_encode_in_the_qr>";
const typeNumber = 0;
const errorCorrectionLevel = 'L';
const qr = qrcode(typeNumber, errorCorrectionLevel);
qr.addData(url);
qr.make();
const cellSize = 10;
const margin = 0;
const qrCodeDataURL = qr.createDataURL(cellSize, margin)
document.getElementById('qrCode1').src = qrCodeDataURL;
</script>
The element defined by qrCode1 is an <img> tags where I set the width and height.
The most important line of the above is qr.createDataURL(cellSize, margin). The cellSize is the fidelity of the cells of the QR code. The larger your display size is of the QR code, the larger cellSize you’ll need. The margin is just a margin around the generate QR code. You can leave this as zero if you’re adding your own margin on the <img> tag.
At the moment my favorite solutions are CDN-served client-side QR generation libraries. There are a ton of them. You don’t need a server-hosted solution.