首页 > 编程 > C# > 正文

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

2020-01-24 02:30:46
字体:
来源:转载
供稿:网友

通常在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#程序设计有所帮助!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表