To create a QR code in JavaScript, you can use a library such as qrcodejs.
Here’s an example of how to use the qrcodejs library to create a QR code:
Include the qrcodejs library in your HTML file:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/qrcode.min.js"></script>
Create a container element in your HTML file where you want the QR code to be displayed:
<div id="qrcode"></div>
In your JavaScript code, create a new QRCode object and specify the container element and the QR code data:
new QRCode(document.getElementById('qrcode'), {
text: 'https://www.example.com',
width: 128,
height: 128,
});
This will create a 128×128 QR code with the text “https://www.example.com” and display it in the qrcode container element.
You can customize the appearance of the QR code by setting various options such as colorDark, colorLight, ecLevel, and others. You can also specify a custom function as the render option to control how the QR code is rendered.
For more information, you can refer to the qrcodejs documentation: https://www.npmjs.com/package/qrcodejs
