看了你的帖子,感觉还是没有解决问题。看来得详细点说:
我希望解决在多框架网页下没有响应单击事件的问题。
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!
我希望解决在多框架网页下没有响应单击事件的问题。
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!
解决方案 »
- urgent!!! a tough task about concurrent programming in VB DCOM
- 如何判断某字段中内容为空len(Trim(rs2.Fields(6).Value)不为0
- delete from 表名 where 条件,是不是‘表名’不能为中文。在线等!!!!!!!
- 求助:我做了一个CD播放器,不能播放,请大家看看我的程序哪有错误!
- 答谢!请yunok近来领分
- 有没有办法判断系统是否装了mdac_typ.exe?
- VB查询MYSQL的语句报错
- 关于VB字符串的高效率操作
- 请教三个条件的if如何编写?
- 我用InstallShiled制作VB的安装程序,遇到一些问题
- 没有窗体的EXE,怎么改变VB自己的图标
- 如何判断与当前月日相等的前三天记录.....
如果弹新窗口会触发NewWindow2事件
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
你的方法改成
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