Created
October 20, 2013 04:19
-
-
Save a-laughlin/7065031 to your computer and use it in GitHub Desktop.
Simple utility to get selected text in a page
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(win,doc){ | |
function _getSelectedText (){ | |
_getSelectedText = win.getSelection ? // redefine itself when first run | |
win.getSelection : | |
doc.getSelection ? | |
doc.getSelection: | |
doc.selection ? | |
function(){return doc.selection.createRange().text;} : | |
function(){return '';}; | |
return _getSelectedText(); | |
} | |
function _deselectText() { | |
_deselectText = win.getSelection ? // redefine itself when first run | |
function(){win.getSelection().removeAllRanges();} : | |
doc.getSelection ? | |
function(){doc.getSelection().removeAllRanges();} : | |
doc.selection ? | |
function(){doc.selection.empty();} : | |
function(){}; | |
return _deselectText(); | |
} | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment