Is there a way in JS to get the entire HTML within the html tags, as a string?
document.documentElement.??
You have to iterate through the document childNodes and getting the outerHTML content.
in VBA it looks like this
For Each e In document.ChildNodes
Put ff, , e.outerHTML & vbCrLf
Next e
using this, allows you to get all elements of the web page including < !DOCTYPE > node if it exists
document.documentElement.innerHTML
MS added the outerHTML
and innerHTML
properties some time ago.
According to MDN, outerHTML
is supported in Firefox 11, Chrome 0.2, Internet Explorer 4.0, Opera 7, Safari 1.3, Android, Firefox Mobile 11, IE Mobile, Opera Mobile, and Safari Mobile. outerHTML
is in the DOM Parsing and Serialization specification.
See quirksmode for browser compatibility for what will work for you. All support innerHTML
.
var markup = document.documentElement.innerHTML;
alert(markup);
The correct way is actually:
webBrowser1.DocumentText
You can do
new XMLSerializer().serializeToString(document)
in browsers newer than IE 9
See https://caniuse.com/#feat=xml-serializer
You can also do:
document.getElementsByTagName('html')[0].innerHTML
You will not get the Doctype or html tag, but everything else...