I was wondering if there is an alternative to using the Javascript: document.documentElement.outerHTML
that possibly utilizes the jQuery selector and other jQuery methods if they exist. Or, if there is any other more efficient ways of getting a string containing the entire source code of a webpage using Javascript and or Jquery.
I was wondering if there is an alternative to using the Javascript: document.documentElement.outerHTML that
Share
That was the quick and easy way but, like someone said, it will only return the HTML within the
<html></html>tags. It would not include stuff found outside of the<html></html>tags, like the doctype.To get everything, you can use
jQuery.ajax()to request the page and get the whole shebang.The request was made synchronously, in this example, so that we could do whatever with the source after the request returns. You could make the call asynchronously and put all of your code in the success function.
Here’s the fiddle
http://jsfiddle.net/4rkdF/