Is there a way in JS to get the entire HTML within the html tags, as a string?
document.documentElement.??
I always use
document.getElementsByTagName('html')[0].innerHTML
Probably not the right way but I can understand it when I see it.
PROBABLY ONLY IE:
> webBrowser1.DocumentText
for FF up from 1.0:
//serialize current DOM-Tree incl. changes/edits to ss-variable
var ns = new XMLSerializer();
var ss= ns.serializeToString(document);
alert(ss.substr(0,300));
may work in FF. (Shows up the VERY FIRST 300 characters from the VERY beginning of source-text, mostly doctype-defs.)
BUT be aware, that the normal "Save As"-Dialog of FF MIGHT NOT save the current state of the page, rather the originallly loaded X/h/tml-source-text !! (a POST-up of ss to some temp-file and redirect to that might deliver a saveable source-text WITH the changes/edits prior made to it.)
Although FF surprises by good recovery on "back" and a NICE inclusion of states/values on "Save (as) ..." for input-like FIELDS, textarea etc. , not on elements in contenteditable/ designMode...
If NOT a xhtml- resp. xml-file (mime-type, NOT just filename-extension!), one may use document.open/write/close to SET the appr. content to the source-layer, that will be saved on user's save-dialog from the File/Save menue of FF. see: http://www.w3.org/MarkUp/2004/xhtml-faq#docwrite resp.
https://developer.mozilla.org/en-US/docs/Web/API/document.write
Neutral to questions of X(ht)ML, try a "view-source:http://..." as the value of the src-attrib of an (script-made!?) iframe, - to access an iframes-document in FF:
<iframe-elementnode>.contentDocument
, see google "mdn contentDocument" for appr. members, like 'textContent' for instance.
'Got that years ago and no like to crawl for it. If still of urgent need, mention this, that I got to dive in ...
Use document.documentElement
.
Same Question answered here: https://stackoverflow.com/a/7289396/2164160