Languages
[Edit]
EN

JavaScript - get all text from the rendered page

0 points
Created by:
Reilly-Collier
860

In this article, we would like to show you how to get all text from the rendered page using JavaScript.

Quick solution:

Note:

The document.body.innerText needs to be obtained after window load event or at the end of the script to make sure that all items are loaded before we get the body element innerText value.

 

Practical example

Edit

In this example, we get the document.body innerText property value on window load event. This approach guarantees that all the resources are loaded before we retrieve the text from the entire web page.

Note:

innerText returns the text visible on the page as seen by the user.

Including <script> element

Edit

In order to include <script> element content, we can use textContent property instead of innerText.

 

References

Edit
  1. HTMLElement.innerText - Web APIs | MDN
  2. Node.textContent - Web APIs | MDN

Alternative titles

  1. JavaScript - get all text from the rendered page
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join