PRB: Trouble Inserting Non-Displayable HTML into Web PageID: Q185140
|
When hosting the WebBrowser control in your applications, inserting non- displayable HTML such as script or comments does not have any affect. This occurs when using any Dynamic HTML (DHMTL) function that allows you to insert HTML, such as insertAdjacentHTML, pasteHTML, outerHMTL, and so forth.
When inserting non-displayable HTML, the Web page is not reparsed.
You must insert some displayable HTML so that the page will be reparsed. This displayable HTML can be hidden so that it does not actually appear on the page. You may use a SPAN or DIV tag with a display style of none to cause HTML to be hidden.
This behavior is by design.
Option Explicit
Private Sub Command1_Click()
Dim str As String
' Insert some HTML comments
str = "<!-- This is a comment -->"
WebBrowser1.Document.body.insertAdjacentHTML "BeforeEnd", str
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://example.microsoft.com/WebPage.htm"
End Sub
Debug.Print WebBrowser1.Document.body.outerHTML
Option Explicit
Private Sub Command1_Click()
Dim str As String
' Insert some hidden HTML before the comment
str = "<span style='display:none'>h</span>" & _
"<!-- This is a comment -->"
WebBrowser1.Document.body.insertAdjacentHTML "BeforeEnd", str
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "http://example.microsoft.com/WebPage.htm"
End Sub
When you execute the statement in step 4 above, the HTML comment now
appears in the document.
For additional information, please see the following article in the
Microsoft Knowledge Base:
Q185128 Insert event handler into Web page from WebBrowser app
For more information, please see the MSDN Web Workshop:
http://msdn.microsoft.com/workshop/default.asp
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Scott Roberts, Microsoft Corporation
Additional query words: insertAdjacentHTML pasteHTML outerHTML kbWebBrowser
Keywords : kbIE400 kbIE401 kbWebBrowser kbIE500
Version : WINDOWS:4.0,4.01
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 30, 1999