Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/Download_PNG.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head><title>Demo page</title></head><body><p> TODO make a nice looking pure client qrcode generator even allow download of the image</p><a id="output"></a><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script><!-- TEST jquery.qrcode.js--><script type="text/javascript" src="../src/qrcode.js"></script><script type="text/javascript" src="../src/jquery.qrcode.js">/*Need to include "../src/qrcode.js" at first*/</script><!-- TEST jquery.qrcode.min.js <script type="text/javascript" src="../jquery.qrcode.min.js"></script>--><script>jQuery(function(){ var aElement = jQuery('#output'); aElement.qrcode( { render: 'canvas', width: 256, height: 256, text: "http://jetienne.com", id: "canvasID" //set ID for canvas element } ); var qrcode = document.getElementById("canvasID"); //get canvas element by ID aElement.attr('href', qrcode.toDataURL("image/png")); //set qrcode from canvas as base64-dataURL aElement.attr('download', 'filename.png'); //add filename in download attribute aElement.attr('title', 'Click to download as PNG-file'); //add title tooltip.})</script></body></html>
Expand Down
2 changes: 1 addition & 1 deletion jquery.qrcode.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/jquery.qrcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
var canvas = document.createElement('canvas');
canvas.width = options.width;
canvas.height = options.height;

if(typeof options.id !== 'undefined' && options.id!==''){
canvas.id = options.id; //set id for canvas element
}

var ctx = canvas.getContext('2d');

// compute tileW/tileH based on options.width/options.height
Expand Down