Last active
December 21, 2023 10:31
-
-
Save devfred/2838004 to your computer and use it in GitHub Desktop.
javascript: Generate QR code on the fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Quick and dirty plugin to generate qr code on the fly | |
@author Frederick King | |
**/ | |
(function($, undefined) { | |
/** | |
Generate qr code on the fly | |
@parameter {object} options | |
**/ | |
$.fn.qrCode = function(options) { | |
var | |
baseUrl = 'https://chart.googleapis.com/chart?cht=qr', | |
width = options.width, | |
height = options.height, | |
data = options.data, | |
url = baseUrl + "&chs=" + width + "x" + height + "&chl=" + encodeURIComponent(data), | |
i = new Image(); | |
i.src = url; | |
this.append(i); | |
return this; | |
} | |
/** | |
@example | |
$('body').qrCode({ | |
width: 250, | |
height: 250, | |
data: 'AWWWW YAAAA' | |
}); | |
**/ | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment