Skip to content

Instantly share code, notes, and snippets.

@reyesyang
Created April 23, 2013 15:26
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 reyesyang/5444523 to your computer and use it in GitHub Desktop.
Save reyesyang/5444523 to your computer and use it in GitHub Desktop.
Method to get selection text.
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment