Jquery generates the QR code. jquery generates the QR code.

Source: Internet
Author: User

Jquery generates the QR code. jquery generates the QR code.

Go to the topic:

Introduce jquery js and jquery-qrcode.js. I will upload the code demo to the resource library later. The code is simple:

It is easier to generate a QR code for non-Chinese characters.

<!DOCTYPE html>If it is a Chinese character or contain Chinese characters, then you need to do some encoding conversion, the UTF-16 to the UTF-8

<! DOCTYPE html> 

The content of convertCN. js is as follows:

function utf16to8(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 += String.fromCharCode(0xE0 | ((c >> 12) & 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;}

The introduction of the third js is customized to solve the problem that Chinese characters cannot be identified. Compared with Java servlet, jquery is faster, more convenient, and relies on fewer plug-ins.


Jquery generates a QR code, but it is not an image. How can I convert the QR code into an image?

No image is output using the Canvas of html5.

I am working on generating a QR code. I want to use js to generate a QR code. However, in this example, there is a font file, which is from SJIS.

In fact, the above js has a small disadvantage, that is, it does not support Chinese by default.
This is related to the js mechanism. The jquery-qrcode library uses charCodeAt () for encoding conversion,
And this method will get its Unicode encoding by default, the general decoder is using UTF-8, ISO-8859-1 and other methods,
English is no problem, if it is Chinese, under normal circumstances Unicode is UTF-16 implementation, length 2 bits, and UTF-8 encoding is 3 bits, so the codec of the QR code does not match.
The solution is of course to convert the string into a UTF-8 before the QR code encoding
Www.onicos.com/..tf.txt

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.