参考The following code can be used to query and delete files in the internet cache (including cookies). A demonstration routine can be found at the bottom of this post. Note, the enumerated type eCacheType is not supported in Excel 97, but can be changed to a list of Public Constants eg. Public Const eNormal = &H1&. Option Explicit '--------------------------Types, consts and structures Private Const ERROR_CACHE_FIND_FAIL As Long = 0 Private Const ERROR_CACHE_FIND_SUCCESS As Long = 1 Private Const ERROR_FILE_NOT_FOUND As Long = 2 Private Const ERROR_ACCESS_DENIED As Long = 5 Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122 Private Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096 Private Const LMEM_FIXED As Long = &H0 Private Const LMEM_ZEROINIT As Long = &H40 Public Enum eCacheType eNormal = &H1& eEdited = &H8& eTrackOffline = &H10& eTrackOnline = &H20& eSticky = &H40& eSparse = &H10000 eCookie = &H100000 eURLHistory = &H200000 eURLFindDefaultFilter = 0& End Enum Private Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type Private Type INTERNET_CACHE_ENTRY_INFO dwStructSize As Long lpszSourceUrlName As Long lpszLocalFileName As Long CacheEntryType As Long 'Type of entry returned dwUseCount As Long dwHitRate As Long dwSizeLow As Long dwSizeHigh As Long LastModifiedTime As FILETIME ExpireTime As FILETIME LastAccessTime As FILETIME LastSyncTime As FILETIME lpHeaderInfo As Long dwHeaderInfoSize As Long lpszFileExtension As Long dwExemptDelta As Long End Type '--------------------------Internet Cache API Private Declare Function FindFirstUrlCacheEntry Lib "Wininet.dll" Alias "FindFirstUrlCacheEntryA" (ByVal lpszUrlSearchPattern As String, lpFirstCacheEntryInfo As Any, lpdwFirstCacheEntryInfoBufferSize As Long) As Long Private Declare Function FindNextUrlCacheEntry Lib "Wininet.dll" Alias "FindNextUrlCacheEntryA" (ByVal hEnumHandle As Long, lpNextCacheEntryInfo As Any, lpdwNextCacheEntryInfoBufferSize As Long) As Long Private Declare Function FindCloseUrlCache Lib "Wininet.dll" (ByVal hEnumHandle As Long) As Long Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long '--------------------------Memory API Private Declare Function LocalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal uBytes As Long) As Long Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long) Private Declare Function lstrcpyA Lib "kernel32" (ByVal RetVal As String, ByVal Ptr As Long) As Long Private Declare Function lstrlenA Lib "kernel32" (ByVal Ptr As Any) As Long 'Purpose : Deletes the specified internet cache file 'Inputs : sCacheFile The name of the cache file 'Outputs : Returns True on success. 'Author : Andrew Baker 'Date : 03/08/2000 19:14 'Notes : 'Revisions : Function InternetDeleteCache(sCacheFile As String) As Boolean InternetDeleteCache = CBool(DeleteUrlCacheEntry(sCacheFile)) End Function 'Purpose : Returns an array of files stored in the internet cache 'Inputs : eFilterType An enum which filters the files returned by their type 'Outputs : A one dimensional, one based, string array containing the names of the files 'Author : Andrew Baker 'Date : 03/08/2000 19:14 'Notes : 'Revisions : Function InternetCacheList(Optional eFilterType As eCacheType = eNormal) As Variant Dim ICEI As INTERNET_CACHE_ENTRY_INFO Dim lhFile As Long, lBufferSize As Long, lptrBuffer As Long Dim sCacheFile As String Dim asURLs() As String, lNumEntries As Long 'Determine required buffer size lBufferSize = 0 lhFile = FindFirstUrlCacheEntry(0&, ByVal 0&, lBufferSize) If (lhFile = ERROR_CACHE_FIND_FAIL) And (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then 'Allocate memory for ICEI structure lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize) If lptrBuffer Then 'Set a Long pointer to the memory location CopyMemory ByVal lptrBuffer, lBufferSize, 4 'Call first find API passing it the pointer to the allocated memory lhFile = FindFirstUrlCacheEntry(vbNullString, ByVal lptrBuffer, lBufferSize) '1 = success If lhFile <> ERROR_CACHE_FIND_FAIL Then 'Loop through the cache Do 'Copy data back to structure CopyMemory ICEI, ByVal lptrBuffer, Len(ICEI) If ICEI.CacheEntryType And eFilterType Then sCacheFile = StrFromPtrA(ICEI.lpszSourceUrlName) lNumEntries = lNumEntries + 1 If lNumEntries = 1 Then ReDim asURLs(1 To 1) Else ReDim Preserve asURLs(1 To lNumEntries) End If asURLs(lNumEntries) = sCacheFile End If 'Free memory associated with the last-retrieved file Call LocalFree(lptrBuffer) 'Call FindNextUrlCacheEntry with buffer size set to 0. 'Call will fail and return required buffer size. lBufferSize = 0 Call FindNextUrlCacheEntry(lhFile, ByVal 0&, lBufferSize) 'Allocate and assign the memory to the pointer lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize) CopyMemory ByVal lptrBuffer, lBufferSize, 4& Loop While FindNextUrlCacheEntry(lhFile, ByVal lptrBuffer, lBufferSize) End If End If End If 'Free memory Call LocalFree(lptrBuffer) Call FindCloseUrlCache(lhFile) InternetCacheList = asURLs End Function 'Purpose : Converts a pointer an ansi string into a string. 'Inputs : lptrString A long pointer to a string held in memory 'Outputs : The string held at the specified memory address 'Author : Andrew Baker 'Date : 03/08/2000 19:14 'Notes : 'Revisions : Function StrFromPtrA(ByVal lptrString As Long) As String 'Create buffer StrFromPtrA = String$(lstrlenA(ByVal lptrString), 0) 'Copy memory Call lstrcpyA(ByVal StrFromPtrA, ByVal lptrString) End Function 'Demonstration routine Sub Test() Dim avURLs As Variant, vThisValue As Variant On Error Resume Next 'Return an array of all internet cache files avURLs = InternetCacheList For Each vThisValue In avURLs 'Print files Debug.Print CStr(vThisValue) Next 'Return the an array of all cookies avURLs = InternetCacheList(eCookie) If MsgBox("Delete cookies?", vbQuestion + vbYesNo) = vbYes Then For Each vThisValue In avURLs 'Delete cookies InternetDeleteCache CStr(vThisValue) Debug.Print "Deleted " & vThisValue Next Else For Each vThisValue In avURLs 'Print cookie files Debug.Print vThisValue Next End If End Sub
控制网页的FORMS行为Private Sub Command2_Click() With WebBrowser1.Document.Forms(0) .c2.Checked = 1 .r1(1).Checked = 1 End With End Sub Private Sub Command2_Click() With WebBrowser1.Document.Forms(0) .d1.Options(1).Selected = 1 End With End Subweb.Document.getElementsByName("D1").Item(0).selectedIndex = 1============================================== <input type="radio" value="n" checked name="notecome">普通 <input type="radio" value="c" name="notecome">原创 <input type="radio" value="z" name="notecome">转帖 <input type="button" value="发送提交" name="button"比如一个网页里有如上代码 我想选择原创 webbrowser中怎么写 Private Sub Command1_Click() WebBrowser1.Navigate "c:\ggg.html" End SubPrivate Sub Command2_Click() Dim x
For Each x In WebBrowser1.Document.All("notecome") If x.Value = "c" Then x.Checked = True End If Next End Sub============================================================================================ 假设你的HTML代码如下:<html> <script> function abcd(){ alert("haha"); return false; } </script><body> <a id = 'xxx' href=# onclick="abcd()">ggggg</a> </body> </html>VB代码如下: Private Sub Command1_Click() WebBrowser1.Navigate "http://www.applevb.com/script_test.html" End SubPrivate Sub Command2_Click() Dim a, b Dim d As IHTMLDocument2
For Each a In WebBrowser1.Document.All Debug.Print a.tagName If (a.tagName = "SCRIPT") Then End If If (a.tagName = "A") Then If a.Id = "xxx" Then a.FireEvent ("onclick") End If End If Next点击Command1浏览这个网页,点击Command2运行其中的脚本abcd。 ==============================================怎么编程把用户名,密码提交到网页上的登录页? 首先在程序中加入Webbrowser控件并加入引用 Microsoft HTML Object Library。 假设你的HTML页面表单代码如下: <form method="POST" action="http://chen/dll/chat/chatmain.exe/RegUser"> <p>请填写下面表单注册(*项为必添项)</p> <p>*姓名<input type="text" name="Name" size="20"></p> <p>*昵称<input type="text" name="NickName" size="20"></p> <p>电子邮件<input type="text" name="EMail" size="20"></p> <p>*密码<input type="text" name="Password" size="20"></p> <p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p> </form> 注意其中元素的type、Name、value属性。然后VB中的代码如下: Private Sub Command1_Click() WebBrowser1.Navigate "http://chen/chat/newuser.htm" End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant) Dim vDoc, vTag Dim i As Integer
Set vDoc = WebBrowser1.Document List1.Clear For i = 0 To vDoc.All.length - 1 If UCase(vDoc.All(i).tagName) = "INPUT" Then Set vTag = vDoc.All(i) If vTag.Type = "text" Or vTag.Type = "password" Then List1.AddItem vTag.Name Select Case vTag.Name Case "Name" vTag.Value = "IMGod" Case "NickName" vTag.Value = "IMGod" Case "Password" vTag.Value = "IMGodpass" Case "EMail" vTag.Value = "[email protected]" End Select ElseIf vTag.Type = "submit" Then vTag.Click End If End If Next i End Sub 点击Command1就可以自动填表并提交了。 ===================================================================================== 调用forms下的Submit控件的Click事件,我会做,但我不想这么做.有没有办法直接调用类似于:web1.document.forms.submit,这句语句我怎么写都不成功 是这个 Webbrowser1.document.formName.submit()不能用,formname为form1所以我调用Webbrowser1.document.form1.submit 出错类型:对象不支持该属性或方法, 然后调用Webbrowser1.document.forms(0).submit() 出错类型同上 Private Sub Command1_Click() WebBrowser1.Navigate "http://localhost/webapplication2/MyLogonPage.aspx" End SubPrivate Sub Command2_Click() WebBrowser1.Document.All("Form1").submit End Sub <form name="form1" method="post" action="aa.asp"> ...... <input name="reset" type="reset" vlaue="reset" class="button"> </form> 我本想把reset的type改成submit 再提交,可出错,type是只读属性,不能修改,我只要有办法把这页面递交出去就行,当然,用POST也不行,参数太多,组合方式太多 你用下面的代码试一下你的页面: Private Sub Command1_Click() WebBrowser1.Navigate "http://oakhome.xicp.net/webapplication2/MyLogonPage.aspx" End SubPrivate Sub Command2_Click() Dim x
On Error Resume Next For Each x In WebBrowser1.Document.All List1.AddItem x.Name Next End Sub看看在List1里面列出来的页面元素的名字有没有Form1 找到原因了,你的页面是这样的: <input language="javascript" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " name="Submit1" id="Submit1" type="submit" value="Submit" /> 你把name="Submit1" 改成name="Submit"肯定就不会成功了,很不幸的是我要提交的页面中就有这样一句,现在可有办法解决吗???======================================================================= 使用WebBrowser_V1接受消息Private WithEvents WebMessage As WebBrowser_V1Private Sub Form_Load() Set WebMessage = WebBrowser1.Object End SubPrivate Sub WebMessage_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)'这里有Flags变量可以取得窗体应有的状态End Sub具体值需要你自己去试试看。对象浏览器里面没有=======================================================================================================通过下面的方法遍历页面中的IFrame: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 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 Debug.Print "Frame: " & pBrowser.LocationURL End If
Loop
Set pEnumerator = Nothing
End If
End Sub =======================================================================================
Option Explicit
'--------------------------Types, consts and structures
Private Const ERROR_CACHE_FIND_FAIL As Long = 0
Private Const ERROR_CACHE_FIND_SUCCESS As Long = 1
Private Const ERROR_FILE_NOT_FOUND As Long = 2
Private Const ERROR_ACCESS_DENIED As Long = 5
Private Const ERROR_INSUFFICIENT_BUFFER As Long = 122
Private Const MAX_CACHE_ENTRY_INFO_SIZE As Long = 4096
Private Const LMEM_FIXED As Long = &H0
Private Const LMEM_ZEROINIT As Long = &H40
Public Enum eCacheType
eNormal = &H1&
eEdited = &H8&
eTrackOffline = &H10&
eTrackOnline = &H20&
eSticky = &H40&
eSparse = &H10000
eCookie = &H100000
eURLHistory = &H200000
eURLFindDefaultFilter = 0&
End Enum
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type INTERNET_CACHE_ENTRY_INFO
dwStructSize As Long
lpszSourceUrlName As Long
lpszLocalFileName As Long
CacheEntryType As Long 'Type of entry returned
dwUseCount As Long
dwHitRate As Long
dwSizeLow As Long
dwSizeHigh As Long
LastModifiedTime As FILETIME
ExpireTime As FILETIME
LastAccessTime As FILETIME
LastSyncTime As FILETIME
lpHeaderInfo As Long
dwHeaderInfoSize As Long
lpszFileExtension As Long
dwExemptDelta As Long
End Type
'--------------------------Internet Cache API
Private Declare Function FindFirstUrlCacheEntry Lib "Wininet.dll" Alias "FindFirstUrlCacheEntryA" (ByVal lpszUrlSearchPattern As String, lpFirstCacheEntryInfo As Any, lpdwFirstCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindNextUrlCacheEntry Lib "Wininet.dll" Alias "FindNextUrlCacheEntryA" (ByVal hEnumHandle As Long, lpNextCacheEntryInfo As Any, lpdwNextCacheEntryInfoBufferSize As Long) As Long
Private Declare Function FindCloseUrlCache Lib "Wininet.dll" (ByVal hEnumHandle As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
'--------------------------Memory API
Private Declare Function LocalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal uBytes As Long) As Long
Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)
Private Declare Function lstrcpyA Lib "kernel32" (ByVal RetVal As String, ByVal Ptr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" (ByVal Ptr As Any) As Long
'Purpose : Deletes the specified internet cache file
'Inputs : sCacheFile The name of the cache file
'Outputs : Returns True on success.
'Author : Andrew Baker
'Date : 03/08/2000 19:14
'Notes :
'Revisions :
Function InternetDeleteCache(sCacheFile As String) As Boolean
InternetDeleteCache = CBool(DeleteUrlCacheEntry(sCacheFile))
End Function
'Purpose : Returns an array of files stored in the internet cache
'Inputs : eFilterType An enum which filters the files returned by their type
'Outputs : A one dimensional, one based, string array containing the names of the files
'Author : Andrew Baker
'Date : 03/08/2000 19:14
'Notes :
'Revisions :
Function InternetCacheList(Optional eFilterType As eCacheType = eNormal) As Variant
Dim ICEI As INTERNET_CACHE_ENTRY_INFO
Dim lhFile As Long, lBufferSize As Long, lptrBuffer As Long
Dim sCacheFile As String
Dim asURLs() As String, lNumEntries As Long
'Determine required buffer size
lBufferSize = 0
lhFile = FindFirstUrlCacheEntry(0&, ByVal 0&, lBufferSize)
If (lhFile = ERROR_CACHE_FIND_FAIL) And (Err.LastDllError = ERROR_INSUFFICIENT_BUFFER) Then
'Allocate memory for ICEI structure
lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize)
If lptrBuffer Then
'Set a Long pointer to the memory location
CopyMemory ByVal lptrBuffer, lBufferSize, 4
'Call first find API passing it the pointer to the allocated memory
lhFile = FindFirstUrlCacheEntry(vbNullString, ByVal lptrBuffer, lBufferSize) '1 = success
If lhFile <> ERROR_CACHE_FIND_FAIL Then
'Loop through the cache
Do
'Copy data back to structure
CopyMemory ICEI, ByVal lptrBuffer, Len(ICEI)
If ICEI.CacheEntryType And eFilterType Then
sCacheFile = StrFromPtrA(ICEI.lpszSourceUrlName)
lNumEntries = lNumEntries + 1
If lNumEntries = 1 Then
ReDim asURLs(1 To 1)
Else
ReDim Preserve asURLs(1 To lNumEntries)
End If
asURLs(lNumEntries) = sCacheFile
End If
'Free memory associated with the last-retrieved file
Call LocalFree(lptrBuffer)
'Call FindNextUrlCacheEntry with buffer size set to 0.
'Call will fail and return required buffer size.
lBufferSize = 0
Call FindNextUrlCacheEntry(lhFile, ByVal 0&, lBufferSize)
'Allocate and assign the memory to the pointer
lptrBuffer = LocalAlloc(LMEM_FIXED, lBufferSize)
CopyMemory ByVal lptrBuffer, lBufferSize, 4&
Loop While FindNextUrlCacheEntry(lhFile, ByVal lptrBuffer, lBufferSize)
End If
End If
End If
'Free memory
Call LocalFree(lptrBuffer)
Call FindCloseUrlCache(lhFile)
InternetCacheList = asURLs
End Function
'Purpose : Converts a pointer an ansi string into a string.
'Inputs : lptrString A long pointer to a string held in memory
'Outputs : The string held at the specified memory address
'Author : Andrew Baker
'Date : 03/08/2000 19:14
'Notes :
'Revisions :
Function StrFromPtrA(ByVal lptrString As Long) As String
'Create buffer
StrFromPtrA = String$(lstrlenA(ByVal lptrString), 0)
'Copy memory
Call lstrcpyA(ByVal StrFromPtrA, ByVal lptrString)
End Function
'Demonstration routine
Sub Test()
Dim avURLs As Variant, vThisValue As Variant
On Error Resume Next
'Return an array of all internet cache files
avURLs = InternetCacheList
For Each vThisValue In avURLs
'Print files
Debug.Print CStr(vThisValue)
Next
'Return the an array of all cookies
avURLs = InternetCacheList(eCookie)
If MsgBox("Delete cookies?", vbQuestion + vbYesNo) = vbYes Then
For Each vThisValue In avURLs
'Delete cookies
InternetDeleteCache CStr(vThisValue)
Debug.Print "Deleted " & vThisValue
Next
Else
For Each vThisValue In avURLs
'Print cookie files
Debug.Print vThisValue
Next
End If
End Sub
With WebBrowser1.Document.Forms(0)
.c2.Checked = 1
.r1(1).Checked = 1
End With
End Sub
Private Sub Command2_Click()
With WebBrowser1.Document.Forms(0)
.d1.Options(1).Selected = 1
End With
End Subweb.Document.getElementsByName("D1").Item(0).selectedIndex = 1==============================================
<input type="radio" value="n" checked name="notecome">普通
<input type="radio" value="c" name="notecome">原创
<input type="radio" value="z" name="notecome">转帖
<input type="button" value="发送提交" name="button"比如一个网页里有如上代码
我想选择原创
webbrowser中怎么写
Private Sub Command1_Click()
WebBrowser1.Navigate "c:\ggg.html"
End SubPrivate Sub Command2_Click()
Dim x
For Each x In WebBrowser1.Document.All("notecome")
If x.Value = "c" Then
x.Checked = True
End If
Next
End Sub============================================================================================
假设你的HTML代码如下:<html>
<script>
function abcd(){
alert("haha");
return false;
}
</script><body>
<a id = 'xxx' href=# onclick="abcd()">ggggg</a>
</body>
</html>VB代码如下:
Private Sub Command1_Click()
WebBrowser1.Navigate "http://www.applevb.com/script_test.html"
End SubPrivate Sub Command2_Click()
Dim a, b
Dim d As IHTMLDocument2
For Each a In WebBrowser1.Document.All
Debug.Print a.tagName
If (a.tagName = "SCRIPT") Then End If
If (a.tagName = "A") Then
If a.Id = "xxx" Then
a.FireEvent ("onclick")
End If
End If
Next点击Command1浏览这个网页,点击Command2运行其中的脚本abcd。
==============================================怎么编程把用户名,密码提交到网页上的登录页?
首先在程序中加入Webbrowser控件并加入引用 Microsoft HTML Object Library。
假设你的HTML页面表单代码如下:
<form method="POST" action="http://chen/dll/chat/chatmain.exe/RegUser">
<p>请填写下面表单注册(*项为必添项)</p>
<p>*姓名<input type="text" name="Name" size="20"></p>
<p>*昵称<input type="text" name="NickName" size="20"></p>
<p>电子邮件<input type="text" name="EMail" size="20"></p>
<p>*密码<input type="text" name="Password" size="20"></p>
<p><input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"></p>
</form>
注意其中元素的type、Name、value属性。然后VB中的代码如下:
Private Sub Command1_Click()
WebBrowser1.Navigate "http://chen/chat/newuser.htm"
End SubPrivate Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim vDoc, vTag
Dim i As Integer
Set vDoc = WebBrowser1.Document
List1.Clear
For i = 0 To vDoc.All.length - 1
If UCase(vDoc.All(i).tagName) = "INPUT" Then
Set vTag = vDoc.All(i)
If vTag.Type = "text" Or vTag.Type = "password" Then
List1.AddItem vTag.Name
Select Case vTag.Name
Case "Name"
vTag.Value = "IMGod"
Case "NickName"
vTag.Value = "IMGod"
Case "Password"
vTag.Value = "IMGodpass"
Case "EMail"
vTag.Value = "[email protected]"
End Select
ElseIf vTag.Type = "submit" Then
vTag.Click
End If
End If
Next i
End Sub
点击Command1就可以自动填表并提交了。
=====================================================================================
调用forms下的Submit控件的Click事件,我会做,但我不想这么做.有没有办法直接调用类似于:web1.document.forms.submit,这句语句我怎么写都不成功
是这个
Webbrowser1.document.formName.submit()不能用,formname为form1所以我调用Webbrowser1.document.form1.submit
出错类型:对象不支持该属性或方法,
然后调用Webbrowser1.document.forms(0).submit()
出错类型同上
Private Sub Command1_Click()
WebBrowser1.Navigate "http://localhost/webapplication2/MyLogonPage.aspx"
End SubPrivate Sub Command2_Click()
WebBrowser1.Document.All("Form1").submit
End Sub
<form name="form1" method="post" action="aa.asp">
......
<input name="reset" type="reset" vlaue="reset" class="button">
</form>
我本想把reset的type改成submit 再提交,可出错,type是只读属性,不能修改,我只要有办法把这页面递交出去就行,当然,用POST也不行,参数太多,组合方式太多
你用下面的代码试一下你的页面:
Private Sub Command1_Click()
WebBrowser1.Navigate "http://oakhome.xicp.net/webapplication2/MyLogonPage.aspx"
End SubPrivate Sub Command2_Click()
Dim x
On Error Resume Next
For Each x In WebBrowser1.Document.All
List1.AddItem x.Name
Next
End Sub看看在List1里面列出来的页面元素的名字有没有Form1
找到原因了,你的页面是这样的:
<input language="javascript" onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); " name="Submit1" id="Submit1" type="submit" value="Submit" />
你把name="Submit1" 改成name="Submit"肯定就不会成功了,很不幸的是我要提交的页面中就有这样一句,现在可有办法解决吗???=======================================================================
使用WebBrowser_V1接受消息Private WithEvents WebMessage As WebBrowser_V1Private Sub Form_Load()
Set WebMessage = WebBrowser1.Object
End SubPrivate Sub WebMessage_NewWindow(ByVal URL As String, ByVal Flags As Long, ByVal TargetFrameName As String, PostData As Variant, ByVal Headers As String, Processed As Boolean)'这里有Flags变量可以取得窗体应有的状态End Sub具体值需要你自己去试试看。对象浏览器里面没有=======================================================================================================通过下面的方法遍历页面中的IFrame: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 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
Debug.Print "Frame: " & pBrowser.LocationURL
End If
Loop
Set pEnumerator = Nothing
End If
End Sub
=======================================================================================