AxWebBrowser & Hide Javascript error windows

D

dricks dr

Hi,

I'm using the AxWebBrowser Control from microsoft in a C# application.
It works fine, but i have many problems to hide the javascript error
windows that appear when u visit a website with... javascript errors :)

I can catch errors coming from website that does not use frames using :
private void NavigateComplete(object
sender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{
mshtml.IHTMLDocument2 doc;
doc = (mshtml.IHTMLDocument2)browser.Document;
mshtml.IHTMLWindow2 window=doc.parentWindow;
HTMLWindowEvents_Event ievent =(HTMLWindowEvents_Event)window;
ievent.onerror+=new
HTMLWindowEvents_onerrorEventHandler(this.WindowError);
}

private void WindowError(string t, string i, int s)
{
//Console.WriteLine("Erreur trouvee");
mshtml.IHTMLDocument2 doc;
doc = (mshtml.IHTMLDocument2)browser.Document;
mshtml.IHTMLWindow2 window=doc.parentWindow;
((IHTMLEventObj)window.@event).returnValue=true;
}

But it does NOT works with websites with Frames.
So i tried to set the event handler on frames too, using :
private void NavigateComplete(object
sender,AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
{

mshtml.IHTMLDocument2 doc;
doc = (mshtml.IHTMLDocument2)browser.Document;

int index = 0;
object o =index ;
object o2 =index ;

if (doc.frames.length>0)
{
for (int i=0;i<doc.frames.length;i++)
{
o=i;
IHTMLWindow2 frame = (IHTMLWindow2)doc.frames.item(ref o);

if (frame.frames.length>0)
{
for (int j=0;j<frame.frames.length;j++)
{

o2=j;
IHTMLWindow2 frame2 = (IHTMLWindow2)frame.frames.item(ref o);
HTMLWindowEvents_Event ievent3
=(HTMLWindowEvents_Event)frame2;
ievent3.onerror+=new
HTMLWindowEvents_onerrorEventHandler(this.WindowError);
}
}

HTMLWindowEvents_Event ievent2 =(HTMLWindowEvents_Event)frame;
ievent2.onerror+=new
HTMLWindowEvents_onerrorEventHandler(this.WindowError);

}
}

mshtml.IHTMLWindow2 window=doc.parentWindow;
HTMLWindowEvents_Event ievent =(HTMLWindowEvents_Event)window;
ievent.onerror+=new
HTMLWindowEvents_onerrorEventHandler(this.WindowError);
}

(ErrorWindow is still the same than before)

But it STILL doesn't work :(

Does someone know why it does not work?
How to fix this??
Help ! :)

F.Mestayer
 
A

Alvin Bruney

bad idea but you can hook into the window.error handler and swallow the
error. it's bad because everything gets swallowed. it's good for you because
it will get rid of the script errors.
 
G

Guest

why not try set WebBrowser Silent to true?
Alvin Bruney said:
bad idea but you can hook into the window.error handler and swallow the
error. it's bad because everything gets swallowed. it's good for you because
it will get rid of the script errors.
 
D

Dricks Dr

Thanx for replying :)

@Alvin Bruney :
I dont understand what you mean with 'hook window error handler'. Could
you precise this please? It should be the right way to avoid those
annoying messages :)

@unknown user :
I can't use Silent=true property because it hides ALL message box,
including login//password message box of web sites, which is annoying :/
 
Joined
Aug 22, 2006
Messages
1
Reaction score
0
I spent few hours fighting this same problem and found a solution.

After I placed the browser.Silent = true; just after the axWebBrowser component had finished to Init, it started to work. (inside InitalizeComponent) :D

Like this:

((System.ComponentModel.ISupportInitialize)(this.browser)).EndInit();

browser.Silent =
true;

this.ResumeLayout(false);


Hope it helps!

Hrannar
 

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