I use the standard System.Windows.Forms.WebBrowser to load and display one web page. WebBrowser emulates version 11 of IE. The page has an iframe and is displayed normally.
I need to get the full HTML code of the page with the contents of the IFrame, but these elements are empty. In the full IE html-code can be seen. I try to receive the text of the code in the following two ways:
public String HtmlDocumentText { get { return webBrowser.DocumentText; } } public String DomDocumentText { get { // REM. http://stackoverflow.com/questions/3640236/converting-htmldocument-domdocument-to-string var document = webBrowser.Document; var documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)document.DomDocument; var content = documentAsIHtmlDocument3.documentElement.outerHTML; return content; } } It seems to me that the problem lies in the security restrictions for this element, because the following code causes an access error:
var frames = webBrowser.DocumentTestToDelete.Window.Frames; var frame1 = webBrowser.DocumentTestToDelete.Window.Frames[0]; var document1 = frame1.Document; Error: Access Denied (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
I note that I managed to get the IFrames code using JavaScript:
string jCode = "var iframe = document.getElementById('frame-id'); var innerDoc = iframe.contentDocument || iframe.contentWindow.document; innerDoc.documentElement.innerHTML"; Object html = webBrowser.WebBrowser.Document.InvokeScript("eval", new object[] { jCode }); But this is not what is necessary, although I could use this approach, but with large labor costs. Maybe there is a way to force WebControl to render full html along with the contents of an IFrame?