I'll give it a try. FYI, I only care about IE6+.
Main Topics
Browse All TopicsIs there a way with Javascript to capture the complete HTML for a web page? I have a function and I'm grabbing some of the HTML with:
<script language='JavaScript'>
if (document.getElementById("
document.getElementById("m
</script>
But I'm not getting all of the HTML. I also tried innerHTML.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
I tried the following code, it works in IE7 but not in Firefox:
<html><head>
<title>Your Title</title>
<script type="text/javascript">
function GetBodySource()
{
var TestedVariable = document.body.outerHTML;
alert(TestedVariable);
}
</script>
</head>
<body onLoad="GetBodySource()">
<h1>Your Page Source Here</h1>
</body></html>
But, if you change "var TestedVariable = document.body.outerHTML;" to var TestedVariable = document.body.innerHTML;" it works in Firefox also. Hope this helps :)
PS - I have tried it on more complex pages also, but there seems to be not problem at all!
What do you mean "structures under the body"? The result should be everything in between the body tags. What did you get? What did you need? If you need it in some "format" (i.e. structure??) then what are you trying to access? InnerHTML won't be the best way to access elements (i.e. tags and contents) inside the body. There are better ways to access specific elements, if that is what you need.
bol
Business Accounts
Answer for Membership
by: b0lsc0ttPosted on 2007-03-02 at 18:08:07ID: 18645655
The DOM will give you access to all of the HTML. However since browser don't always handle it the same the results can be different. If you wanted to try innerHTML then you should use.
ame('body' );
var body = document.getElementsByTagN
body[0].innerHTML;
I don't know how well supported that will be but that would be the correct way to get the "contents" (including html) of the body tag. You could even use html instead of body if you wanted the head section too.
Let me know how this helps. If you want to clarify what you need this for then there may be a better way to do it, especially if it will be more reliable in different browsers. Let me know if you have a question or need more information.
bol