View Full Version : retrieve and store url's html page source in java script variable

03-22-2012, 09:21 AM
we have an url link in our java script. then how to retrieve and store url's html page source in java script variable ?

if any one know solution please help me asap...

03-22-2012, 09:30 AM
I don't think you can get a pages source code* using javascript. You'd have to use php.

*You do mean source code don't you?

03-22-2012, 02:18 PM
I would generally agree. However, using javascript it is possible to read the current state of the page from and including the opening head tag down to and including the closing body tag. This will be how the browser interprets the document's innerHTML property, which varies. Some see the current state of the DOM, others more of the original source code depending upon if and how the DOM was changed. A real time test or tests could probably be performed to determine which. Cookies aren't suitable for this (too much data), but localStorage could be used to save the data on the user's computer for later retrieval on the web site that stored it there for that one user.

For anything more permanent (localStorage, like cookies can be cleared by the user), or to be available to more than the one user who saved it for retrieval, a server side solution would be required.

And, regardless of method, one should consider if the entire page is what one really wants to save. More likely there are certain key pieces of information that would suffice.