控制网页的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=# onclick="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"