使用了WebBrowser控件,截取了WebBrowser控件的Click事件后,web页面不能跳转。
html文件代码如下:
<html>
<head>
<title>登录.gif</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">td img {display: block;}</style>
<!--Fireworks CS3 Dreamweaver CS3 target.  Created Mon Dec 01 17:14:00 GMT+0800 2008-->
</head>
<body  bgcolor="#ffffff" topmargin="0" leftmargin="0">
   <a href="通知.htm">通知</a>
   <a href="设置.htm">设置</a>
</body>
</html>VB代码如下:
Private WithEvents M_Dom As MSHTML.HTMLDocumentPrivate Function M_Dom_oncontextmenu() As Boolean
    M_Dom_oncontextmenu = False
End FunctionPrivate Function M_Dom_onclick() As Boolean
Dim strUserAccount As String
Dim strPassword As String
Dim oEvent As CEventObj    On Error GoTo ErrHandle
        Set oEvent = M_Dom.parentWindow.event
        oEvent.returnValue = True
        '点击提交
        If (LCase(oEvent.srcElement.Id) = LCase("btnSubmit")) Then
            strUserAccount = M_Dom.documentElement.All("txtUserAccount").Value
            strPassword = M_Dom.documentElement.All("txtPassword").Value
            Debug.Print "账号:" & strUserAccount
            Debug.Print "密码:" & strPassword
            MsgBox LoadResString(110) & strUserAccount & vbCrLf & _
                   LoadResString(111) & strPassword, vbOKOnly + vbInformation
        End If
        
        Exit Function
        
ErrHandle:
    Call ErrorProcess("frmMain.M_Dom_onclick()", Err.Source, Err.Number, Err.Description, "")
End FunctionPrivate Sub wbMain_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    On Error GoTo ErrHandle
        wbMain.Document.body.Style.BorderStyle = "none"
        wbMain.Document.body.Scroll = "no"
        Set M_Dom = wbMain.Document
    Exit Sub
    
ErrHandle:
    Call ErrorProcess("frmMain.wbMain_NavigateComplete2()", Err.Source, Err.Number, Err.Description, "")
End Sub

解决方案 »

  1.   

    试试放到timer中执行 比如interval设置为500ms false,然后click后设置其为true,主要是让其跳出webbrowser的事件
      

  2.   

    你M_Dom_onclick返回True就可以了
    Private Function M_Dom_onclick() As Boolean 
    Dim strUserAccount As String 
    Dim strPassword As String 
    Dim oEvent As CEventObj     On Error GoTo ErrHandle         M_Dom_onclick=True        Set oEvent = M_Dom.parentWindow.event 
            oEvent.returnValue = True 
            '点击提交 
            If (LCase(oEvent.srcElement.Id) = LCase("btnSubmit")) Then 
                strUserAccount = M_Dom.documentElement.All("txtUserAccount").Value 
                strPassword = M_Dom.documentElement.All("txtPassword").Value 
                Debug.Print "账号:" & strUserAccount 
                Debug.Print "密码:" & strPassword 
                MsgBox LoadResString(110) & strUserAccount & vbCrLf & _ 
                      LoadResString(111) & strPassword, vbOKOnly + vbInformation 
            End If 
            
            Exit Function 
            
    ErrHandle: 
        Call ErrorProcess("frmMain.M_Dom_onclick()", Err.Source, Err.Number, Err.Description, "") 
    End Function