QRCode.js is a cross-browser compatibility JavaScript library which helps you to generate QR codes on the fly at client-side. "QRCode.js" uses HTML5 Canvas and HTML5 Tables to display the QR code. The library has no dependencies whatsoever. To generate a QR code, you just include the JavaScript library and then pass the required parameters to the QRCode function, the text you want to encode as the QR code, the width & height of the QR code you want to display, as well as your specified foreground color and background color.

Create a simple HTML div (optionally set a height and width with CSS):

  1. <style>
  2. #divqrcode {
  3. width: 102px;
  4. height: 102px;
  5. margin-top: 14px;
  6. }
  7. </style>
  8. <div id="divqrcode"></div>
Complete code to generate QR code with default configuration:
  1. <!DOCTYPE HTML>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>JQuery QRCode Example</title>
  5. <!--<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  6. <meta name="viewport" content="width=device-width, initial-scale=2,user-scalable=no" />-->
  7. <style>
  8. #divqrcode {
  9. width: 102px;
  10. height: 102px;
  11. margin-top: 14px;
  12. }
  13. </style>
  14. <script src="Scripts/jquery-latest.min.js"></script>
  15. <script type="text/javascript" src=" Scripts/qrcode.min.js"></script>
  16. </head>
  17. <body>
  18. <h1 style="margin-top:147px;">JQuery QRCode Demo</h1> Please enter your input:
  19. <input id="texInput" type="text" value="SantoshA" /><br />
  20. <div id="divqrcode"></div>
  21. <script type="text/javascript">
  22. var qrcode = new QRCode($("#divqrcode"),
  23. {
  24. width: 102,
  25. height: 102,
  26. });
  27. function generateCode()
  28. {
  29. var _text = $("#texInput");
  30. if (!_text.value)
  31. {
  32. alert("Enter your input!");
  33. _text.focus();
  34. return;
  35. }
  36. qrcode.makeCode(_text.value);
  37. }
  38. generateCode();
  39. $("#texInput").
  40. on("blur", function()
  41. {
  42. generateCode();
  43. }).
  44. on("keydown", function(e)
  45. {
  46. if (e.keyCode == 13)
  47. {
  48. generateCode();
  49. }
  50. });
  51. </script>
  52. </body>
Output

Output

Browser Compatibility

IE8~10, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, Windows Mobile, etc.

Required files: