软件编程
位置:首页>> 软件编程>> C#编程>> WinForm开发中屏蔽WebBrowser脚本错误提示的方法

WinForm开发中屏蔽WebBrowser脚本错误提示的方法

作者:shichen2014  发布时间:2021-06-23 08:49:40 

标签:WinForm,WebBrowser,错误,提示

通常在C#的实际开发过程中,会发现设置其属性ScriptErrorsSuppressed无法达到屏蔽脚本错误效果,但是可以通过下面两种方式实现这一效果。

1.在DocumentCompleted事件中订阅Error处理,代码如下所示:


private void wbGoogleMap_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
 wbGoogleMap.Document.Window.Error += new HtmlElementErrorEventHandler(Window_Error);
}
void Window_Error(object sender, HtmlElementErrorEventArgs e)
{
 e.Handled = true;
}

2.在脚本中window.onerror中处理,代码如下所示:


window.onerror = function(error, url, line) {
//      log(error + "url:" + url + "lineNo:" + line);
 return true;
}

通过上述两种方法能够很好的屏蔽WebBrowser脚本错误提示。希望本文所述方法对大家的C#程序设计有所帮助!

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com