Removing alerts from WebBrowser control

S

Sin Jeong-hun

Is it possible to modify the HTML or the script of a WebBrowser
control in DocumentCompleted event? I tried to modify it but that
caused DocumentCompleted again so the program fell in an endless loop.
The reason I'm trying to do so is to remove some specific scripts like
"alert()" because it locks up the WebBrowser control. When there's an
alert box is open, calling Navigate causes an exception. I need other
scripts to be executed so I cannot turn the entier Javascript off.

So in short, how can I modify the html in DocumentComplete event
before alert() is executed?
 
N

Nicholas Paldino [.NET/C# MVP]

Sin Jeong-hun,

How are you loading the HTML? Are you dynamically generating it or are
you loading it from the web/a file.

If you are loading it from a file, I would modify the contents of the
file before you load it.

If you are loading it from the web, then I would download the content
into a MemoryStream first and then modify the contents of the file, then
passing it to the DocumentStream property of the WebBrowser control.

Hope this helps.
 

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