在vb中调用javascript功能函数并将结果反映到WebBrowser上

控制网页的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 Sub 

web.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 Sub 

Private 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=# οnclick="abcd()">ggggg</a> 
</body> 
</html> 

VB代码如下: 
Private Sub Command1_Click() 
WebBrowser1.Navigate "http://www.applevb.com/script_test.html" 
End Sub 

Private 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 Sub 

Private 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 = "IMGod@paradise.com" 
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 Sub 

Private 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也不行,参数太多,组合方式太多
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值