Can javascript read webpage?


can my page Javascript read same page which itself is loaded? Like other parts of page are dynamically loaded by other provider. I have tried many things, google as well, but now I am in doubt that it is posible. Or it is.

Thank You!

Problem courtesy of: Balvonas


If the page has loaded and the javascript you are running is client-side (which it should be), you should be able to access everything on the page via the document object. I would advise reading about the DOM to familiarise yourself with this.

EDIT: removed link

Solution courtesy of: Tro


Server side code (whether written in JavaScript or otherwise) is not capable of determining the final rendering of the page in the user's browser.

You could build the entire page yourself (and you could use a headless browser, like PhantomJS, to do it) but that could give different results to a visitor's as you would have a different set of cookies, a different source IP address, and so on.

Discussion courtesy of: Quentin

This recipe can be found in it's original form on Stack Over Flow.