


Summary of generating QR code images with JavaScript_javascript skills
Summary:
This is how Baidu Encyclopedia introduces QR codes: QR code (Quick Response Code), also known as 2D barcode, is a black and white code that uses specific geometric figures distributed on a plane (two-dimensional direction) according to certain rules. The alternate graphics are a key to all information data. In modern commercial activities, a wide range of applications can be realized, such as: product anti-counterfeiting/tracing, advertising push, website links, data downloads, commodity transactions, positioning/navigation, e-commerce applications, vehicle management, information transmission, etc. Nowadays, the application of the scan (referred to as 313) function on smartphones has made QR codes more common. With the vigorous development of the domestic Internet of Things industry, more QR code technology application solutions have been developed, and QR codes have become the entrance to the mobile Internet. Really become a reality.
We can see QR codes everywhere when surfing the Internet, so how to generate QR codes on the front end? Today I will share the front-end generation of QR codes.
Introduction:
QRCode.js is a js library that supports HTML5 canvas and table markup in the DOM across browsers. What we use is based on QRCode.js.
Browser:
IE6~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, ETC.
jquery-qrcode:
jquery-qrcode features: simple operation, small size, only 14k after compression, but does not support Chinese encoding.
<script src="http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script> <script type="text/javascript" src="../jquery.qrcode.min.js"></script> <div id="qrcode"></div> <script> $(function(){ $('#qrcode').qrcode("http://www.cnblogs.com/xiyangbaixue"); // 更详细的配置 // $('#qrcode').qrcode({ // text: "http://www.cnblogs.com/xiyangbaixue", // 要编码的字符串 // width: 50, // 定义宽度 // height: 50, // 定义高度 // background: "#ccc", // 背景色 // foreground: "red" // 前景色 // }); }) </script>
Effect:
qrcodejs:
Features of qrcodejs: The Chinese-generated QR code will not appear garbled when scanned, and you can choose which element to use to draw the QR code.
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="qrcode.js"></script> <div id="qrcode"></div> <script> new QRCode(document.getElementById("qrcode"), "http://www.cnblogs.com/xiyangbaixue"); // 或者 // new QRCode(document.getElementById("qrcode"), { // text: "http://www.cnblogs.com/xiyangbaixue", // width: 50, // height: 50, // background: "#ccc", // foreground: "red" // }); </script>
Use svg:
<script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="qrcode.js"></script> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <g id="qrcode"/> </svg> <script type="text/javascript"> var qrcode = new QRCode(document.getElementById("qrcode"), { width : 100, height : 100, useSVG: true }); qrcode.makeCode("http://www.cnblogs.com/xiyangbaixue"); // qrcode.clear(); // 清除二维码 </script>
Effect:
Configuration parameters:
render string
Configure which node element is used to draw the QR code. The options are table, svg and canvas
The default selection order is canvas -> svg -> table
text string
String to encode
Default: ""
width number
The length of the QR code, the unit is px
It should be noted that when using table or svg to draw the QR code, it will be appropriately reduced so that the dimension of the QR code matrix can be divided.
Default: 256
height number
The width of the QR code, the unit is px
It should be noted that when using table or svg to draw the QR code, it will be appropriately reduced so that the dimension of the QR code matrix can be divided.
Default: 256
correctLevel number
The error correction level can be 0, 1, 2, or 3. The larger the number, the greater the required error correction level
Default: 3
background color
Background color
Default: #FFFFFF
foreground color
Foreground color
Default: #000000

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
