Help and Support

PRB: Trouble Inserting Non-Displayable HTML into Web Page

Article ID:185140
Last Review:May 11, 2006
Revision:2.0
This article was previously published under Q185140
On This Page

SYMPTOMS

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 (DHTML) function that allows you to insert HTML, such as insertAdjacentHTML, pasteHTML, outerHMTL, and so forth.

Back to the top

CAUSE

When inserting non-displayable HTML, the Web page is not reparsed.

Back to the top

RESOLUTION

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.

Back to the top

STATUS

This behavior is by design.

Back to the top

MORE INFORMATION

Steps to Reproduce Behavior

1.Open a new Standard EXE project.
2.Add the WebBrowser control to your form.
3.Add a Command Button and the following code. This code inserts an HTML comment into a Web page. For information about inserting script, please refer to the Knowledge Base article in the references section of this article.
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
					
4.Execute the following code to check to see if the HTML was inserted.
Debug.Print WebBrowser1.Document.body.outerHTML
					
You'll notice that in this case, the HTML was not inserted.

Back to the top

Resolution

Insert displayable HTML before the non-displayable HTML. Do this by using a SPAN tag with the display style set to none.
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.

Back to the top

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base: 185128 (http://support.microsoft.com/kb/185128/EN-US/) Insert event handler into Web page from WebBrowser app For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/ (http://msdn.microsoft.com/ie/)

http://support.microsoft.com/iep (http://support.microsoft.com/iep)

Back to the top


APPLIES TO
Microsoft Internet Explorer 4.0 128-Bit Edition
Microsoft Internet Explorer 4.01 Service Pack 2
Microsoft Internet Explorer 5.0

Back to the top

Keywords: 
kbdhtml kbfaq kbpending kbprb kbwebbrowser KB185140

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.