Modify a document before shown in WebBrowser

G

Guest

Is there any way to modify a document before it is displayed by a
System.Windows.Forms.WebBrowser control? The Navigating event occurs before
the document is loaded, but it does not expose the document object. On the
other hand, the DocumentCompleted event exposes the document object, but it
occurs after the WebBrowser has loaded the document. What I want is
something like a DocumentCompleting event (which does not exist) that would
allow me to customize specific documents for the user before the documents
are loaded by the WebBrowser.

Thanks,
Lance
 
C

Cor Ligthert [MVP]

LjLeven,

This you need as first step 2005
DirectCast(WebBrowser1.Document.DomDocument,
mshtml.IHTMLDocument2).designMode = "On"

And than the rest from MSHTML, see the samples for that on MSDN.

If somebody has an alternative to set that designmode, than I will be glad
to see this.

I hope this helps,

Cor
 
G

Guest

Thanks for the idea. It seems like the type of thing that I am looking for.
Do you know which event I should handle in order to modify the document
before it is shown by the WebBrowser?

Thanks again,
Lance
 
P

Peter Huang [MSFT]

Hi

We can do that in the DocumentCompleted event.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Me.WebBrowser1.Navigate("www.google.com")
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal
e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles
WebBrowser1.DocumentCompleted
Try
Dim doc As HtmlDocument = sender.Document
Dim he As HtmlElement = doc.GetElementById("2a")
MsgBox(he.InnerText)
he.InnerText += "Test"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Yes, that is the idea. The problem with that technique is that the document
can briefly appear in the unmodified state before the document's text is
modified and redisplayed. Is there any way to modifiy the document before it
is displayed by the WebBrowser?

Thanks again,
Lance
 
P

Peter Huang [MSFT]

Hi

Based on my research, the DocumentComplete Event Fires when a document has
been completely loaded and initialized.
It is the only time it has been downloaded complete but not displayed by IE.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top