I am new to JavaScript, and I want to know if there is a way, or ways, to get the whole text from a web-page, which means the text a person can read on a webpage (excluding any images' text).
1 Answer
You should be able to use:
document.body.innerText;
4 Comments
vaibhav.dec
Hi, Thanks for ur quick reply this is working but i m getting some squire boxes type text. how can i remove these..
defau1t
share the url where you are getting square boxes.
defau1t
If you are talking about the square boxes on the botom of SO. then these are html entries there.
vaibhav.dec
I am using below scrip String s = "var allLinks = document.getElementsByTagName('*'); " + "var str = document.body.innerText.replace(/\\s*/g, ' ');" + //.replace(/\\s*/g, ' ');" //replace(/</?[a-zA-Z0-9]+>|<[a-zA-Z0-9]+\\s*/>|\r?\\n/g,' ') "alert(str);"; And at yahoo.com I m getting the [][][][][] type boxes.