Skip to content

Instantly share code, notes, and snippets.

@chrisevans
Forked from atk/LICENSE.txt
Created November 21, 2011 21:38
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 chrisevans/1384034 to your computer and use it in GitHub Desktop.
Save chrisevans/1384034 to your computer and use it in GitHub Desktop.
QR-Codify - add QR-Code to link

QR-Codify

Small JS snippet to add an QR code to a given link.

Usage

func([link node]) // -> Adds a 99x99px QR Code with the href to the node

function(
l, // link node
i // placeholder for image
){
// add newly created image i (currently without source) to link
l.appendChild(
i=new Image()
);
// set image source to use the google chart api to create the QR-Code
i.src='//chart.apis.google.com/chart?cht=qr&chs=99x99&chld=M|0&chl='+l.href;
}
function(l,i){l.appendChild(i=new Image());i.src='//chart.apis.google.com/chart?cht=qr&chs=99x99&chld=M|0&chl='+l.href;}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Alex Kloss <alexthkloss@web.de>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "QRcodify",
"description": "Adds QR-Code to link",
"keywords": [
"link",
"QR-Code",
"smartphone"
]
}
<!DOCTYPE html>
<title>Foo</title>
<div>Expected result: the following link contains a QR-Code pointing to the 140byt.es Homepage:</div>
<div>Result:<br/><a id="ret" href="http://140byt.es">140byt.es </a></div>
<script>
// write a small example that shows off the API for your example
// and tests it in one fell swoop.
var myFunction = function(l,i){l.appendChild(i=new Image());i.src='//chart.apis.google.com/chart?cht=qr&chs=99x99&chld=M|0&chl='+l.href;}
myFunction(document.getElementById( "ret" ));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment