So is it possible to snag the entire content of a page in its current state. For example, if interacting with a page, via jquery, I've modified the document by either inserting content, or by adding or removing class names. Is it possible to get the markup of this document in its current form from starting html tag to html tag?
+4
A:
Can't you just get the root object in the DOM and call innerHTML to get it all?
Lloyd
2009-05-14 22:02:36
Yes we can! - think I heard this phrase somewhere else
Richard
2009-05-14 22:03:44
Either Bob the Builder or Barack Obama
David Caunt
2009-05-14 22:04:21
Or Dora the Explorer
Erik Forbes
2009-05-14 22:42:11
No wait, that's "We can do it, nothing to it!" - and it's Diego, not Dora. *sigh*
Erik Forbes
2009-05-14 22:42:34
+2
A:
Something like
document.documentElement.innerHTML
This doesn't include the <html> opening and closing tags
David Caunt
2009-05-14 22:07:56
I think on IE you can use document.documentElement.outerHTML and don't have to add "<html>" and "</html>".
Alexander Klimetschek
2009-05-14 22:16:16
+1
A:
just call $('html').html() using jquery to get page source.
<html>
<head>
<title>Just a test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#showContent').click(function(event){
event.preventDefault();
var pageSource = '<html>' + $('html').html() +'</html>';
alert(pageSource);
});
});
</script>
</head>
<body>
<a href="#" id="showContent" >show content</a>
</body>
</html>
Andrea Balducci
2009-05-14 22:19:30
That rocks, but is there any way to get at the <html> tags and any other text in the page? ie: DOCTYPE declarations, etc?I'm working on a "passive" markup scraper for w3c validation concerns and need to have access to the full, rendered html of the page being displayed.
kdawg
2010-02-19 16:42:08