Skip to content

Instantly share code, notes, and snippets.

@findel
Last active December 14, 2015 14:18
Show Gist options
  • Save findel/5099737 to your computer and use it in GitHub Desktop.
Save findel/5099737 to your computer and use it in GitHub Desktop.
Bookmarklets to give you a QR code for selected HTML or text. Copy each to a bookmark.
javascript:
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;
}
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
html = document.selection.createRange().htmlText;
}
}
window.open('http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + html);
javascript:
var selected = "";
if (typeof window.getSelection != "undefined") {
selected = window.getSelection();
} else if (typeof document.selection != "undefined") {
if (document.selection.type == "Text") {
selected = document.selection;
}
}
window.open('http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=' + selected);
@findel
Copy link
Author

findel commented Mar 6, 2013

Credit for the selection code: http://stackoverflow.com/questions/4652734/return-html-from-a-user-selection/4652824#4652824

But just noticed that it's also selecting HTML. Might not want that.

@findel
Copy link
Author

findel commented Mar 6, 2013

Added qr-my-text-selection.js for non-HTML selection.

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