Created
March 7, 2012 20:33
-
-
Save carlcarl/1995926 to your computer and use it in GitHub Desktop.
javascript text selection
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
<head> | |
<script type="text/javascript"> | |
function GetSelectedText () { | |
if (window.getSelection) { // Firefox, Opera, Google Chrome and Safari | |
var range = window.getSelection (); | |
alert (range.toString ()); | |
} | |
else { | |
if (document.selection.createRange) { // Internet Explorer | |
var range = document.selection.createRange (); | |
alert (range.text); | |
} | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<button onclick="GetSelectedText ()">Get the selected text!</button> | |
Select some text! | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment