Skip to content

Instantly share code, notes, and snippets.

@devfred
Last active December 21, 2023 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devfred/2838004 to your computer and use it in GitHub Desktop.
Save devfred/2838004 to your computer and use it in GitHub Desktop.
javascript: Generate QR code on the fly
/**
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