0

I need to get all of the text in a Chrome page that I highlight with my mouse, I know very little about javascript but I found this:

var text = "";
if (window.getSelection){
    text = window.getSelection().toString();
    console.log(text)
} else if (document.selection && document.selection.type != 
"Control") {
         text = document.selection.createRange().text;
     }
}

Which works once, so is there a good way to iterate this so each time I highlight it prints what I highlighted?

Tylerr
  • 201
  • 2
  • 12

1 Answers1

0

from https://stackoverflow.com/a/28425297/2553191:

Take a look at the select DOM event on MDN.

It fires once the mouse or key is released (at least in Chrome 40).

document.addEventListener('select', callback);

ehacinom
  • 8,070
  • 7
  • 43
  • 65