QRCode.js

repository·master·Indexed 12 days ago

https://github.com/davidshimjs/qrcodejs

A lightweight, dependency-free JavaScript library for generating QR Codes using HTML5 Canvas and DOM table tags. Supports customization of dimensions, colors, and error correction levels via the QRCode class.

Tokens
520
Snippets
3
Records
3
Agent score
46%

What's inside qrcode.js

  1. Generate a basic QRCode

    master

    To create a simple QRCode, instantiate the QRCode class by passing a DOM element and the text string you want to encode. The library will automatically render the code into the provided container.

    <div id="qrcode"></div>
    <script type="text/javascript">
    new QRCode(document.getElementById("qrcode"), "http://jindo.dev.naver.com/collie");
    </script>
  2. Configure QRCode options

    master

    You can customize the appearance and behavior of the QRCode by passing an options object as the second argument to the QRCode constructor.

    Available options:

    • text: The string to encode.
    • width: The width of the QRCode in pixels.
    • height: The height of the QRCode in pixels.
    • colorDark: The color of the dark modules (e.g., #000000).
    • colorLight: The color of the light modules (e.g., #ffffff).
    • correctLevel: The error correction level using QRCode.CorrectLevel constants.
    <div id="qrcode"></div>
    <script type="text/javascript">
    var qrcode = new QRCode(document.getElementById("qrcode"), {
    	text: "http://jindo.dev.naver.com/collie",
    	width: 128,
    	height: 128,
    	colorDark : "#000000",
    	colorLight : "#ffffff",
    	correctLevel : QRCode.CorrectLevel.H
    });
    </script>
  3. Update or clear a QRCode instance

    master

    Once a QRCode instance is created, you can manipulate it using the following methods:

    • clear(): Removes the existing QRCode from the container.
    • makeCode(text): Generates a new QRCode with the provided text string.
    qrcode.clear(); // clear the code.
    qrcode.makeCode("http://naver.com"); // make another code.