Created
May 2, 2012 18:37
-
-
Save lemieuxster/2579060 to your computer and use it in GitHub Desktop.
QR Code Bookmarklet
This file contains hidden or 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
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); |
This file contains hidden or 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
//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); |
Chrome now has this functionality built in, FYI.
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
Thx for sharing this @lemieuxster !