比如网页中有两个按钮,原本按钮1是弹出一个新窗口,访问www.sina.com,按钮2是弹出一个新窗口,访问www.sohu.com,能否修改后让按钮1访问www.163.com,按钮2访问www.126.com?也就是修改其中的代码,只需要将其中的www.sina.com替换成www.163.com、www.sohu.com替换成www.126.com,(注:假定上面的代码如www.sina.com、www.sohu.com都能从“查看源文件”里面直接看到),谢谢。
调试欢乐多
CComPtr<IHTMLElement> spDispElements;
hr=spDocument2->get_body(&spDispElements);
得到spDispElements后,spDispElements->get_innerHTML(保存数据的wstring)
然后就是替换wstring中你需要改的内容,接着spDispElements->put_innerHTML(新的wstring)
楼上的意思大约是:webbrowser1.document.body.innerHTML=新的内容吗(该方法无效)?还是每个元素的innerHTML?
Private Sub Command1_Click()
texbody.innerHTML = "<h1>动态生成网页</h1>"
End Sub
Private Sub Form_Load()
WebBrowser1.Navigate "about:"
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Set texbody = WebBrowser1.Document.body
End Sub注意vb6 的对象必须用set 赋值直接 webbrowser1.document.body.innerHTML=××× 是无效的
Dim tint As Integer
'得到html的所有元素
Set docobj = Me.WebBrowser1.Document
'循環查找hidden元素
For tint = 0 To docobj.All.length - 1 If UCase(docobj.All(tint).tagName) = "INPUT" Then Set tagobj = docobj.All(tint) If tagobj.Type = "hidden" Then If tagobj.Name = "ulogin" Then
tagobj.Value = usernm
End If If tagobj.Name = "upsw" Then
tagobj.Value = userpsw
End If If tagobj.Name = "httpurl" Then
tagobj.Value = getsvrIP & "/" & getsvrsitenm
End If End If
End If Next看看這樣能不能改變他的onclick的值
WebBrowser1.Navigate "http://www.baidu.com"
End SubPrivate Sub Command2_Click()
WebBrowser1.Document.body.innerHTML = Replace(WebBrowser1.Document.body.innerHTML, "www.baidu.com", "www.lolong.com")
End Sub