Get all page content?

Thus, you can lock the entire contents of the page in its current state. For example, when interacting with a page through jquery, I changed the document by pasting the contents, or adding or removing class names. Is it possible to get the markup of this document in its current form from running the html tag to the html tag?

+4
source share
3 answers

Can't you just get the root object in the DOM and call innerHTML to get it all?

+5
source

Sort of

document.documentElement.innerHTML 

This does not include <html> opening and closing tags.

+7
source

just call $ ('html'). html () using jquery to get the 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> 
+4
source

All Articles