axWebBrowser control and javascript errors

  • Thread starter Thread starter Greg B
  • Start date Start date
G

Greg B

hi all,

Has anyone come across working code for a Windows Forms application
that uses AxWebBrowser control and is capable of intercepting and
dealing with the 'Internet Explorer Script Error' (An error has
occured in the script on this page') type errors. I know the
WebBrowser control (the one that comes by default in Visual Studio
Toolbox) has 'ScriptErrorsSuppressed' property that seems to achieve
just that, but I don't have much time left for re-implementation.

After doing some searching on the web, some of the possible solutions
that I've seen included:

1) setting aXWebBrowser.Silent = true at an appropriate time. The
downside of this approach is that some of the pop-ups are useful, such
as authentication prompts etc.

2) implementing IOleDocumentSite, IOleClientSite and IDocHostShowUI
interfaces and using IDocHostShowUI::ShowMessage for the purpose of
intercepting the message box. I have attempted this but am yet to see
the ShowMessage function invoked...

3) implementing IOleCommandTarget and the QueryStatus and Exec
methods, and then watching out for the Exec invocation with
OLECMDID_SHOWSCRIPTERROR. From what I understand this behaviour
doesn't work if Disable Script Debugging check box is cleared in
Internet Explorer settings.

apologies that this post is not actually directly related to
HtmlEditor :|

regards,
Greg
 
hi all,

Has anyone come across working code for a Windows Forms application
that uses AxWebBrowser control and is capable of intercepting and
dealing with the 'Internet Explorer Script Error' (An error has
occured in the script on this page') type errors. I know the
WebBrowser control (the one that comes by default in Visual Studio
Toolbox) has 'ScriptErrorsSuppressed' property that seems to achieve
just that, but I don't have much time left for re-implementation.

After doing some searching on the web, some of the possible solutions
that I've seen included:

1) setting aXWebBrowser.Silent = true at an appropriate time. The
downside of this approach is that some of the pop-ups are useful, such
as authentication prompts etc.

2) implementing IOleDocumentSite, IOleClientSite and IDocHostShowUI
interfaces and using IDocHostShowUI::ShowMessage for the purpose of
intercepting the message box. I have attempted this but am yet to see
the ShowMessage function invoked...

3) implementing IOleCommandTarget and the QueryStatus and Exec
methods, and then watching out for the Exec invocation with
OLECMDID_SHOWSCRIPTERROR. From what I understand this behaviour
doesn't work if Disable Script Debugging check box is cleared in
Internet Explorer settings.

apologies that this post is not actually directly related to
HtmlEditor :|

regards,
Greg

You might also want to check out the WebRequest class
 
Placing

m_htmlDoc = (IHTMLDocument2)axWebBrowser1.Document;
HTMLWindowEvents2_Event onErrorEvent;
onErrorEvent = (HTMLWindowEvents2_Event)m_htmlDoc.parentWindow;
onErrorEvent.onerror += new
HTMLWindowEvents2_onerrorEventHandler(myHTMLWindowEvents2_onerror);


in DocumentComplete handler, and implementing the onerror handler as:


void myHTMLWindowEvents2_onerror(string description, string url, int
line)
{
IHTMLEventObj evtObj = m_htmlDoc.parentWindow.@event;
if (evtObj != null)
{
evtObj.returnValue = true;
}
}


seemed to get the job done on my XP SP2 work machine, but when I take
my executable and run it on Windows 2003 or Windows 2000 test box,
the
onerror handler doesn't appear to be called. I saw some post which
said that I should be specifying my onerror handler in
NavigateComplete2 (instead of my DocumentComplete), but I wasn't
quite
sure exactly what to do with NavigateComplete2 handler parameters
(I've tried IHTMLDocument2 doc =
((AxSHDocVw.AxWebBrowser)sender).Document as IHTMLDocument2; and
SHDocVw.IWebBrowser2 brow = e.pDisp as SHDocVw.IWebBrowser2; but the
onerror handler was never invoked)
 
Back
Top