Last active
November 27, 2017 16:24
-
-
Save peacefulseeker/a50eae4ba2dc7bdc537565abe8a5b512 to your computer and use it in GitHub Desktop.
JavaScript - return the current selection
This file contains 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
function getSelected() { | |
if (window.getSelection) { | |
return window.getSelection().toString(); | |
} else if (document.getSelection) { | |
return document.getSelection().toString(); | |
} else { | |
var selection = document.selection && document.selection.createRange(); | |
if (selection.text) { | |
return selection.text.toString(); | |
} | |
return ""; | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment