How to get the text content of the entire document?

I am creating a Chrome extension that at some point should determine the current language of the page. For this, my plan is to extract the text content of the page (or at least part of it) and transfer it to the api translation. However, I could not find any simple way to just get all the textNode document.

There is a backup plan that must recursively parse $('body').contents() until there is enough textual content, but it will be a bit flaky. Perhaps there is a better way?


Note. The Chrome api extensions allow your script to access the dom user page as if it were part of it.

+7
javascript jquery google-chrome google-chrome-extension
source share
4 answers

Using the jQuery text () method

 $('body').text() 
+9
source share

Javascript:

 document.body.textContent 
+11
source share

Without jQuery, just as simple: document.body.innerText;

+10
source share
0
source share

All Articles