Generate a QR code and a QR code with Parameters

Source: Internet
Author: User

Generate a QR code and a QR code with Parameters

This article describes a jquery-based QR code generation plug-in qrcode. You can call this plug-in on the page to generate the corresponding QR code.

 

1. First, add the jquery library file and qrcode plug-in to the page.

<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.qrcode.min.js"></script> 

2. Add a div in the page layout

<Div class = "modal-body" id = "qrCode"> var str = "http: //" + location. host + "/ActivityDetail.html? Id = "+ row. activityGuid + "& isMail =" + row. isMail + ""; $ ("# qrCode "). empty (); $ ('# qrCode '). qrcode (str); // $ ('# qrCode '). qrcode ("http://www.helloweba.com"); // any string

4. During the experiment, we found that the two-dimensional code could not recognize Chinese content. We found that jquery-qrcode was converted using charCodeAt. And this method will get its Unicode encoding by default, if there is Chinese content, in the generation of the QR code before the string to the UTF-8, and then generate a QR code. You can use the following functions to convert Chinese strings:

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 += 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;    } 

You can directly write this method into the referenced plug-in and call it later. As follows:

Var str = toUtf8 ("2017 rooster success! "); $ ('# QrCode'). qrcode (str );

  

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.