• 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
  • 相关阅读:
    结合<span id="outer"><span id="inter">text</span></span>这段结构,谈谈innerHTML、outerHTML、innerText之间的区别
    字符串的方法slice、substr、substring对比
    为什么两个一样的对象,用===打印是false
    this指向
    复制对象的方法
    Promise以及async和await的用法
    前端性能优化&&网站性能优化
    P1510 精卫填海
    分解质因数
    P2648 赚钱
  • 原文地址:https://www.cnblogs.com/james1207/p/3325138.html
Copyright © 2020-2023  润新知