本文介绍了AxWeb浏览器和隐藏Javascript错误窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!



我正在C#应用程序中使用Microsoft的AxWebBrowser控件.
它工作正常,但是我有很多问题要隐藏javascript错误
您访问带有以下内容的网站时出现的窗口... javascript错误:)

我可以使用:
捕获来自不使用框架的网站的错误私有void NavigateComplete(object
发件人,AxSHDocVw.DWebBrowserEvents2_NavigateComple te2Event 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.WindowEr ror);
}

私有void WindowError(字符串t,字符串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;
}

但是它不适用于带有Frames的网站.
所以我也尝试使用:
在框架上设置事件处理程序私有void NavigateComplete(object
发件人,AxSHDocVw.DWebBrowserEvents2_NavigateComple te2Event e)
{

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

int索引= 0;
对象o = index;
对象o2 = index;

如果(doc.frames.length> 0)
{
对于(int i = 0; i< doc.frames.length; i ++)
{
o = i;
ihtmlwindow2 frame =(IHTMLWindow2)doc.frames.item(ref" o);

if ="(frame.frames.length ="> 0)
{
对于(int j = 0; j

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_NavigateComple te2Event 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.WindowEr ror);
}

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_NavigateComple te2Event 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

推荐答案

public class MyWebBrowser : System.Windows.Forms.WebBrowser
{
    private SHDocVw.IWebBrowser2 Iwb2;

    protected override void AttachInterfaces(object nativeActiveXObject)
    {
        Iwb2 = (SHDocVw.IWebBrowser2) nativeActiveXObject;
        Iwb2.Silent = true;
        base.AttachInterfaces(nativeActiveXObject);
    }

    protected override void DetachInterfaces()
    {
        Iwb2 = null;
        base.DetachInterfaces();
    }
}


SHDocVw.IWebBrowser2.Silent = true



C)如果网页是您自己编写的,则最好在其中添加javascript onerror代码.



C)if the web pages written by youself, you had better add javascript onerror code inside.


这篇关于AxWeb浏览器和隐藏Javascript错误窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:38