WinForm开发中屏蔽WebBrowser脚本错误提示的方法
作者:shichen2014 时间:2021-06-23 08:49:40
通常在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#程序设计有所帮助!
标签:WinForm,WebBrowser,错误,提示
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
WPF InkCanvas基本操作方法详解
2023-07-29 06:26:59
![](https://img.aspxhome.com/file/2023/1/70441_0s.gif)
C# 获取客户端IPv4地址的示例代码
2022-09-12 12:39:34
Unity的IPostprocessBuild实用案例深入解析
2023-05-29 05:54:49
java 开发中网络编程之IP、URL详解及实例代码
2023-08-06 10:26:29
用Flutter开发自定义Plugin的方法示例
2023-07-05 00:19:40
![](https://img.aspxhome.com/file/2023/3/99793_0s.png)
Java开发微信公众号接收和被动回复普通消息
2022-04-07 12:30:44
Java服务假死之生产事故的排查与优化问题
2022-01-12 04:03:37
![](https://img.aspxhome.com/file/2023/7/67477_0s.png)
Springboot实现高吞吐量异步处理详解(适用于高并发场景)
2023-08-20 23:40:35
详解C# 中的正则表达式运用
2023-04-20 06:35:03
在Spring Boot中从类路径加载文件的示例
2023-11-11 21:53:44
Java(TM) Platform SE binary 打开jar文件的操作
2021-10-02 00:08:12
![](https://img.aspxhome.com/file/2023/4/62534_0s.jpg)
妙解Java中的回调机制(CallBack)
2022-07-15 15:25:31
C# List 并发丢数据问题原因及解决方案
2023-06-18 17:53:54
深入了解Java数据结构和算法之堆
2022-07-23 19:45:49
![](https://img.aspxhome.com/file/2023/8/77058_0s.png)
java定义数组的三种类型总结
2022-06-27 01:44:44
美化java代码,从合理注释开始
2022-01-18 16:32:47
Java中实现多线程关键词整理(总结)
2023-09-08 16:08:49
Java线程中sleep和wait的区别详细介绍
2021-08-27 02:23:12
如何动态替换Spring容器中的Bean
2023-05-22 20:18:59
springcloud Zuul动态路由的实现
2021-10-07 06:15:40
![](https://img.aspxhome.com/file/2023/0/67140_0s.png)