views:

1471

answers:

5

Is there a way in JS to get the entire HTML within the html tags, as a string?

  document.documentElement.??
+1  A: 

I believe document.outerHTML should return that for you.

Edit: As the MSDN page on the outerHTML property notes, there is no standard that supports this, although IE 6+ and more recently several other browsers now support it. Colin's answer links to the W3C quirksmode page, which offers a good comparison of cross-browser compatibility (for other DOM features too).

Noldorin
Not all browsers support this.
Colin Burnett
@Colin: Yeah, good point. From experience, I seem to remember that both IE 6+ and Firefox support it, though the quirksmode page you linked suggests otherwise...
Noldorin
Firefox does not support OuterHTML. It is IE proprietary. https://developer.mozilla.org/En/Migrate_apps_from_Internet_Explorer_to_Mozilla#Generate_and_manipulate_content
Jesse Dearing
@Jesse: Yes, evidently. Might have been innerHTML that I used, which does have cross-browser support.
Noldorin
A: 
document.documentElement.outerHTML
Brian Campbell
Not all browsers support this.
Colin Burnett
+2  A: 
document.documentElement.innerHTML
cherouvim
+12  A: 

MS added the outerHTML and innerHTML some time ago but they aren't universally supported. See quirksmode for browser compatibility for what will work for you. All support innerHTML however (except Konqueror).

var txt = document.documentElement.innerHTML;
alert(txt);
Colin Burnett
A: 

The correct way is actually:

webBrowser1.DocumentText

Damiano