7,766
社区成员
发帖
与我相关
我的任务
分享
<FRAMESET border=0 frameSpacing=0 COLS="50%,*" frameBorder=0>
<FRAME name=topFrame src="http://www.baidu.com">
<FRAME name=topFrame src="http://www.google.com">
</FRAMESET>
Private Sub Command1_Click()
' MsgBox WebBrowser1.Document.frames.length'这行会显示2,表示有两个frame框架
' MsgBox WebBrowser1.Document.frames(0).Document.body.innerhtml'这行代码提示拒绝访问
WebBrowser1.Document.frames(0).Document.getElementsByName("wd")(0).Value = "测试"'赋值失败,提示拒绝访问
End Sub
' 为运行本程序,应在“菜单->工程->部件”中添加“Microsoft Internet Controls”
' 并在“菜单->工程->引用”中添加“Microsoft HTML Object Library”
Sub EnumFrames(ByVal wb As WebBrowser)
Dim pContainer As olelib.IOleContainer
Dim pEnumerator As olelib.IEnumUnknown
Dim pUnk As olelib.IUnknown
'Dim pBrowser As SHDocVw.IWebBrowser2
Dim pBrowser As SHDocVwCtl.WebBrowser_V1
Set pContainer = wb.Object.Document
' Get an enumerator for the frames
If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
' Enumerate and refresh all the frames
Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next
' Clear errors
Err.Clear
' Get the IWebBrowser2 interface
Set pBrowser = pUnk
If Err.Number = 0 Then
For i = 0 To pBrowser.Document.All.length - 1
If UCase(pBrowser.Document.All(i).tagName) = "A" Then
'List1.AddItem pBrowser.All(i).href
Debug.Print Now & pBrowser.Document.All(i).href
Debug.Print Now & pBrowser.Document.All(i).innterHTML
pBrowser.Document.All(i).Click
'Exit For
End If
Next
Debug.Print "Frame: " & pBrowser.LocationURL
End If
Loop
Set pEnumerator = Nothing
End If
End Sub
' 为运行本程序,应在“菜单->工程->部件”中添加“Microsoft Internet Controls”
' 并在“菜单->工程->引用”中添加“Microsoft HTML Object Library”,添加“Edanmo's OLE interfaces & functions v1.4”
Private Sub Command1_Click()
Dim pContainer As olelib.IOleContainer
Dim pEnumerator As olelib.IEnumUnknown
Dim pUnk As olelib.IUnknown
Dim pBrowser As SHDocVwCtl.WebBrowser_V1
Set pContainer = WebBrowser1.Object.Document
If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next
Err.Clear
Set pBrowser = pUnk
If Err.Number = 0 Then
If pBrowser.LocationURL = "http://www.baidu.com/" Then
pBrowser.Document.getElementsByName("wd")(0).Value = "测试"
Exit Sub
End If
End If
Loop
Set pEnumerator = Nothing
End If
End Sub