Skip to content

Instantly share code, notes, and snippets.

@lemieuxster
Created May 2, 2012 18:37
Show Gist options
  • Save lemieuxster/2579060 to your computer and use it in GitHub Desktop.
Save lemieuxster/2579060 to your computer and use it in GitHub Desktop.
QR Code Bookmarklet
javascript:(function(window, document, undefined) {try {var selectedText = document.getSelection().toString(); if (selectedText === ''){selectedText = window.location.href;} if(selectedText !== ''){var baseQRUrl = 'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + encodeURIComponent(selectedText); window.open(baseQRUrl, '_blank', 'width=400,height=400');}} catch (e) {}})(window, document);
//Opens a window with a QR code for either selected text on the page or the current page URL if no text is selected.
//Bookmarklet-ify it by removing whitespace and prepending javascript:
//Like so: javascript:(function ....)()
(function(window, document, undefined) {
try {
var selectedText = document.getSelection().toString();
if (selectedText === '') {
selectedText = window.location.href;
}
if (selectedText !== '') {
var baseQRUrl = 'http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + encodeURIComponent(selectedText);
window.open(baseQRUrl, '_blank', 'width=400,height=400');
}
} catch (e) {
}
})(window, document);
@lemieuxster
Copy link
Author

Chrome now has this functionality built in, FYI.

@AznCanuck
Copy link

True, thank you, but I still use this bookmarklet as it's already a part of my workflow. Plus it's cross-browser, whereas Chrome's implementation has not trickled down to the Chromium-based browsers yet at this time (just checked Microsoft Edge for Android). I'm a Firefox user myself and it seems not native to that browser yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment