Using Jquery.qrcode.js to generate large-size QR code

Source: Internet
Author: User
Tags jquery library

The function of two-dimensional code

1) mobile device sweep, easy to "take" reading (that is, the URL to generate a two-dimensional code)

2) information can be passed (simply generate a QR code)


Third-party Open source libraries

Project Source: Https://github.com/jeromeetienne/jquery-qrcode

Qrcode.js Core Function Library of two-dimensional code implementation

Jquery.qrcode.js uses jquery to encapsulate the core library of functions. Using it to achieve graphical rendering is actually drawing (supports canvas and table two ways).


How to use

1) Introduction of the jquery Library

2) Introduction of Qrcode.js

3) Introduction of Jquery.qrcode.js

4) Write

var str = "http://www.baidu.com";//var str = "Hello world";//var str = "Chinese to add a function";//var str = ToUtf8 (str); Some functions are to solve the Chinese garbled $ ("#qrcode"). QRCode ({render: "canvas",//Set render mode, value "Canvas" or "table", omitted as "canvas" text:str,//unique required fields, QR Code information width:200,//wide, omitted to 256pxheight:200,//high, omitted to 256pxbackground: "#fff",//two-D code background color, omitted to #fffforeground: "#0f0"//two-D code foreground color, Omit to #000

Solve Chinese garbled characters

Jquery.qrcode.js This library is encoded using the charCodeAt () method, which by default obtains its Unicode encoding. So the Chinese will be garbled, the solution is to put the following function in Qrcode.js last.

function ToUtf8 (str) {      var out, I, Len, C;      out = "";      len = str.length;      for (i = 0; i < len; i++) {      c = str.charcodeat (i);      if ((c >= 0x0001) && (c <= 0x007F)) {out          + = Str.charat (i);      } else if (C > 0x07ff) {out          + = S Tring.fromcharcode (0xE0 | ((c >> b) & 0x0F));          Out + = String.fromCharCode (0x80 | ((c >>  6) & 0x3F));          Out + = String.fromCharCode (0x80 | ((c >>  0) & 0x3F));      } else {          out + = String.fromCharCode (0xC0 | ((c >>  6) & 0x1F));          Out + = String.fromCharCode (0x80 | ((c >>  0) & 0x3F);}      }      return out;  }


Using Jquery.qrcode.js to generate large-size QR code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.