Home > Web Front-end > JS Tutorial > body text

JS implements a method to generate a QR code from a link and convert it into a picture

亚连
Release: 2018-05-29 16:31:04
Original
2658 people have browsed it

This article mainly introduces the JS method of generating QR codes from links and converting them into pictures, involving qrcodejs plug-in and js picture generation related operation skills. Friends in need can refer to the following

Examples of this article Use JS to implement the method of generating a QR code from a link and converting it into a picture. Share it with everyone for your reference, the details are as follows:

<p id="code"></p>
<img id="img"/>
<script type="text/javascript">
  var qrcode=$("#code").qrcode({
    render:&#39;canvas||table&#39;,
    width: 200, //宽度
    height:200, //高度
    text: "http://www.baidu.com" //任意内容
  }).hide();
  var canvas=qrcode.find(&#39;canvas&#39;).get(0);
  //如果有循环,此句必不可少 qrcode.find(&#39;canvas&#39;).remove();
  var data = canvas.toDataURL(&#39;image/jpg&#39;);
  $(&#39;#img&#39;).attr(&#39;src&#39;,data) ;
  saveFile(data,"fd范德萨范德萨");
  //转为图片的方法,需要上门的data
  function saveFile(data,filename){
    var save_link=document.createElementNS(&#39;http://www.w3.org/1999/xhtml&#39;, &#39;a&#39;);
    save_link.href=data;
    save_link.download=filename;
    var event=document.createEvent(&#39;MouseEvents&#39;);
    event.initMouseEvent(&#39;click&#39;,true,false,window,0,0,0,0,0,false,false,false,false,0,null);
    save_link.dispatchEvent(event);
  };
</script>
Copy after login

The above is what I compiled for everyone, I hope it will be helpful to everyone in the future.

Related articles:

Example of how to return to the homepage of the sharing page of the WeChat applet

Detailed explanation of VUE's response to ElTableColumn in element-ui Extension

Detailed explanation of Vue custom dynamic component instance

The above is the detailed content of JS implements a method to generate a QR code from a link and convert it into a picture. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!