zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    ubuntu jdk安装
    paxos 算法略解
    java 异常问题 (望解答)
    jquery加载问题
    The Pragmatic Programmer Quick Reference Guide
    车辆调度管理系统开发(三)
    车辆调度管理系统开发(二)
    车辆调度管理系统开发(一)
    vue2过渡&动画
    VScode 之快速创建vue模板
  • 原文地址:https://www.cnblogs.com/james1207/p/3325138.html
Copyright © 2011-2022 走看看