看了你的帖子,感觉还是没有解决问题。看来得详细点说:
我希望解决在多框架网页下没有响应单击事件的问题。
Private WithEvents WBDoc As HTMLDocumentPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim htm As IHTMLDocument2
    On Error Resume Next
    Set htm = WebBrowser1.document
    Set WBDoc = htm
End Sub
Private Function WBdoc_Onclick() As Boolean
    WBdoc_Onclick = True
    AllowPop = True
End Function
然后我在WebBrowser1_NewWindow2事件里面判断AllowPop = True而决定打开新窗口。但问题是在多框架下,WBdoc_Onclick没有执行,那么AllowPop也就无法得到True了,这样我就无法打开新窗口了。请告诉我在多框架网页下如何使AllowPop = True!

解决方案 »

  1.   

    只要是webbrowser中的元素 。。点击连接如果不弹新穿口都会触发WB_BeforeNavigate2事件
    如果弹新窗口会触发NewWindow2事件
      

  2.   

    多谢解答。但是我的目的是根据AllowPop = True来判断是否弹出新窗体,如果在BeforeNavigate2里面AllowPop = True,那么无法阻止自动弹出窗口。如果不在BeforeNavigate2里面AllowPop = True,那么在多框架下无法触发WBdoc_Onclick。
      

  3.   

    1.多框架先得得到其中某一框架的document
    doc为当前多框架document,strFrames为frame名称,如有嵌套以','分割
    Public Function getDocFromFrames(doc As IHTMLDocument, ByVal strFrames As String) As IHTMLDocument
        On Error GoTo LabErr
        Dim docTmp As IHTMLDocument
        Dim str() As String
        Dim i As Integer
        
        Set docTmp = doc
        str = Split(strFrames, ",")    For i = 0 To UBound(str) - 1
            Set docTmp = docTmp.frames.Item(Trim(str(i))).Document
        Next
        Set getDocFromFrames = docTmp
        Exit Function
    LabErr:
        'MsgBox Err.Description
    End Function2.截获单击元素
    Private WithEvents hdocCur As HTMLDocument 
    Private Sub hdocCur_onmousedown()
        If flagDoEvents Then
            addEvent hdocCur, strUrl, btnName
        End If
    End SubPrivate Sub addEvent(doc As HTMLDocument, strUrl As String, btnValue As String)
    On Error GoTo LblErr
        Dim oEvent As CEventObj
        Dim ele As IHTMLElement
        Dim eleBtn As IHTMLElement    '是否需截获的页面        
        If StrComp(doc.location, Trim(strUrl), vbTextCompare) = 0 Then
            Set oEvent = doc.parentWindow.event'得到触发事件
            Set eleBtn = oEvent.srcElement'得到触发事件按钮
            
            '是否所需按钮
            If StrComp(eleBtn.getAttribute("value"), Trim(btnValue), vbTextCompare) = 0 Then
                '加入所需事件
                eleBtn.Click'模拟原来单击事件
            End If
        End If
    LblErr:
        'MsgBox Err.Description
    End Sub
      

  4.   

    也许上次没说清楚,要响应doc_onClick()必须先得到doc,如doc为框架页,还要得到某个框架页的文档,方法为上一楼的第一个方法,注第二个参数最后还要加个','号,要直接在框架页得元素,我也不知怎么做,正在试验,如成功后告诉你。
    你的方法改成
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
        Dim htm As IHTMLDocument2
        On Error Resume Next
        Set htm = WebBrowser1.document
        Set WBDoc = getDocFromFrames(htm,"frame1,")
    '上一句改过了,frame1为你要响应事件的框架名,如框架里还有嵌套,以,分割
    End Sub
      

  5.   

    得到框架页源码doc.body.innerHtml,然后查看源代码