/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script language=javascript> function getSelText() {     var txt = '';     if (window.getSelection)     {         txt = window.getSelection();             }     else if (document.getSelection)     {         txt = document.getSelection();             }     else if (document.selection)     {         txt = document.selection.createRange().text;             }     else return; document.aform.selectedtext.value = txt; } </script> <input type="button" value="Get selection" onmousedown="getSelText()"> <form name=aform > <textarea name="selectedtext" rows="5" cols="20"></textarea> </form>