jquery generates two-dimensional code and implements image download

Source: Internet
Author: User

1, the introduction of jquery two JS files

<script src= ". /scripts/erweima/jquery-1.10.2.min.js "></script><script type=" Text/javascript "src=". /scripts/erweima/jquery.qrcode.min.js "></script>

2. Prepare a div that shows the QR code

<div id= "Output" style= "margin:0px Auto" ></div>

3, generate two-dimensional code JS

$ ("#output"). empty (); JQuery (' #output '). QRCode ("QR code content");//QR code generation

The result of the two-dimensional code after generation

4. Two-dimensional code save

Since the two-dimensional code is generated after the use of H5 Canvas label display in the JSP page, so the QR code to save as a picture is also a lot of convenience. Canvas provides a method.

  
function Download () {
var data = $ ("Canvas") [0].todataurl (). Replace ("Image/png", "image/octet-stream;"); /Gets the QR code value and modifies the response header.
var filename= "tupian.png";//Save the picture name and format, canvas default to use the PNG format. This format works best. var save_link = document.createelementns (' http://www.w3.org/1999/xhtml ', ' a '); Save_link.href = data; save_link.download = filename; var event = document.createevent (' mouseevents '); Event.initmouseevent (' Click ', True, false, window, 0, 0, 0, 0, 0, False, False, False, FALSE, 0, null); Save_link.dispatchevent (event);
}

  

jquery generates two-dimensional code and implements image download

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.