| The code is as follows |
Copy Code |
| <script type= "Text/javascript" >
Description: Gets the selected text on the page function Getselectedtext () { if (window.getselection) { This technique was the most likely to be standardized. GetSelection () returns a Selection object, which we do not document. Return Window.getselection (). toString (); } else if (document.getselection) { This is the older, simpler technique that returns a string return Document.getselection (); } else if (document.selection) { This is the ie-specific technique. We Don't document the IE selection property or TextRange objects. Return Document.selection.createRange (). text; } }
</script> |
Under FireFox to get input or textarea selected text, you can use the following method:
| code is as follows |
copy code |
| <script type=" Text/javascript "> //Description: FireFox get input or The text selected in TextArea Function gettextfieldselection (e) { if (E.selectionstart!= un Defined && e.selectionend!= undefined) { var start = e.selection Start; var end = E.selectionend; return e.value.substring (start, end); } else Return ""; //not supported on this browser } </script> |