Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyway to grab entire HTML page with javascript?

Status
Not open for further replies.

tlhawkins

Programmer
Dec 28, 2000
797
US

having trouble submitting this, so if we end up with 2 copies I'm sorry :)

anyway, I'm trying to find a way to grab the entire HTML page with javascript. I know it sounds silly, but I want to do it, any ideas?

Thanks
 
Off-hand, one can think of at least two methods both with some limitation(s).
[tt]
function doit() {
if (window.ActiveXObject) {
var oxmlhttp=new ActiveXObject("Msxml2.xmlhttp");
} else if (window.XMLHttpRequest) {
var oxmlhttp=new XMLHttpRequest();
}
oxmlhttp.open("GET",window.location,false);
oxmlhttp.send(null);
var s=oxmlhttp.responseText;
oxmlhttp=null;
alert(s);
}
function doit2() {
var s="<head>\n"+document.getElementsByTagName("head")[0].innerHTML+"\n</head>\n";
s+="<body>\n"+document.body.innerHTML+"\n</body>\n";
alert(s);
}[/tt]
 
Thanks,

I do see the limitations of both but that will have to do, unless someone knows a better way that can grab the DOCTYPE and all that without reloading the page?

-Travis
 
I don't think you really see the limitation, at least not the bit of DOCTYPE, whatever you mean. It is not off-limit.
 
Maybe I don't?
The problem I see with function doit() is that it requires time to completely reload the page but you get a complete page, unless of course there is some session/cookie work that will keep the page from loading again, for instance if it was a purchase process and a confirmation page, hopefully it won't do another purchase...

on the other hand doit2() is not goint to get the:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
DocType tag. ALSO, if the page is not well formed HTML there could be trouble, for instance a page with 2 body tags (some interstitial pages use this method) then it's going to take more work to get the HTML correct.

Are there other limitations besides these? or is there a way to get the DOCTYPE tag with doit2()?

Thanks
 
I wonder what is the original question worded?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top