Posted By

Pjotor on 06/28/10


Tagged

url plugin google jquery prototype QRcode


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

romainsauger


easy QR code


 / Published in: JavaScript
 

URL: http://pjotor.com/snipplr/qr/

This "plug in" (only a url builder really) returns the path to a QR code built by google chart api with the code of your choice and optional size (2:nd argument, 160px default).

Usage: $().qrcode("hello world") or $().qrcode("hello world",100)

Update! Added prototype version. Rebuilds image to a QRcode from the google charts API;

ex. document.getElementById("myImage").qrcode("hello world") makes the image with ID "myImage" to a QRcode with value "hello world"

  1. Bookmarklet:
  2. <a href='javascript:(function(s){var img = new Image();img.width=img.height=300;img.src="http://chart.apis.google"+".com/chart?cht=qr&chl="+encodeURIComponent(s)+"&chs=300x300";img.style.position="fixed";img.style.top=".5em";img.style.right=".5em";img.style.zIndex="1338";img.onclick=function(){this.style.display="none";};document.body.appendChild(img);})(document.location.href);'>QR-this</a>
  3.  
  4. // jQuery plug in
  5. (function ($) {
  6. $.fn.qrcode = function(s,size) {
  7. size = size || 160;
  8. var api = "http://chart.apis.google.com/chart?cht=qr";
  9. var url=api+"&chl="+encodeURIComponent(s);
  10. url+="&chs="+size+"x"+size;
  11. if(s) return url;
  12. }
  13. })(jQuery);
  14.  
  15. // native Object prototype
  16. Object.prototype.qrcode = function(s,size){
  17. size = size || 160;
  18. var src = "http://chart.apis.google.com/chart?cht=qr&chl="+
  19. encodeURIComponent(s)+"&chs="+size+"x"+size;
  20. this.width = this.height = size;
  21. this.title = s;
  22. this.src = src;
  23. return this
  24. }

Report this snippet  

You need to login to post a comment.