Get selected text


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function getSelText() {
  2.  
  3. var s = '';
  4.  
  5. if (window.getSelection) {
  6. s = window.getSelection();
  7. }
  8. else if (document.getSelection) {
  9. s = document.getSelection();
  10. }
  11. else if (document.selection) {
  12. s = document.selection.createRange().text;
  13. }
  14.  
  15. return s;
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.