Posted By

noah on 03/23/07


Tagged

select text copy interactive


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

shachi
vali29
letosword
loric


copy selected text


 / Published in: JavaScript
 

This function returns the text that the user currently has selected.

  1. function getSelectedText(){
  2. if (window.getSelection){
  3. txt = window.getSelection();
  4. }
  5. else if (document.getSelection) {
  6. txt = document.getSelection();
  7. }
  8. else if (document.selection){
  9. txt = document.selection.createRange().text;
  10. }
  11. else return;
  12. return txt;
  13. }

Report this snippet  

You need to login to post a comment.