• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

VB.NET让webbrowser控件中JS脚本错误最新方法(2013-09-16)

 

最近也是在项目中遇到了webbrowser控件中想关闭JS脚本错误窗口的问题,所以经过多次测试,终于用一段高效实用的代码完美解决webbrowser控件中JS脚本错误窗口关闭的问题。


通过创建一个子线程,然后在子线程中不断的去查找各类webbrowser的弹出窗口(alert、JS错误窗口),然后通过sendmessage函数来关闭窗口实现该功能!


webbrowser 脚本错误、webbrowser控件脚本错误代码

VB.NET让webbrowser控件不显示JS脚本错误最新办法,完美解决了


以下代码可以解决webbrowser控件中的JS脚本错误窗口、alert窗口等各种浏览器弹出的窗口,能自动关闭

VB.NET代码如下:


Declare Auto Function SendMessage Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, _
                ByVal wparam As Integer, ByVal lparam As IntPtr) As IntPtr

Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal parentHandle As IntPtr, ByVal childAfter As IntPtr, _
                 ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr

Public Const WM_CLOSE = &H10

Private Sub threadCheckError()
    Dim hwnd As IntPtr
    While 1
        hwnd = FindWindowEx(0, 0, "Internet Explorer_TridentDlgFrame", "Internet Explorer 脚本错误")
        If hwnd.ToInt64 > 0 Then
            SendMessage(hwnd, WM_CLOSE, 0, 0)
        End If

        hwnd = FindWindowEx(0, 0, "#32770", "来自网页的消息")
        If hwnd.ToInt64 > 0 Then
            SendMessage(hwnd, WM_CLOSE, 0, 0)
        End If

        System.Threading.Thread.Sleep(100)
        My.Application.DoEvents()
    End While
End Sub

Dim threadchk As New Threading.Thread(AddressOf threadCheckError)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    WebBrowser1.ScriptErrorsSuppressed = False
    threadchk.Start()
End sub

 

 

 

posted @ 2013-09-16 20:28  Class Xman  阅读(467)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3