Dim X As String Private Sub Command1_Click() With WebBrowser1.Document .Open .write Replace(X, "学习", "<span style='background-color: #FFFF00'>学习</span>") .Close End With End SubPrivate Sub Form_Load() X = "<body>好好学习,天天向上</body>" WebBrowser1.Navigate2 ("about:blank") Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE DoEvents Loop With WebBrowser1.Document .Open .write X .Close End With End Sub
northwolves(狼行天下) : 怎么样对浏览的网页操作呢?能不能在不刷新的情况下进行呢?
因为Find方法需要通过IOLECommandTarget接口来实现,通过VB实现很难,下面是VB.NET 和Delphi的实现方法:HOW TO: Invoke the Find, View Source, and Options Dialog Boxes for the WebBrowser Control from Visual Basic .NEThttp://support.microsoft.com/kb/311288/EN-US/ How to call the Find dialog in WebBrowser http://delphi.about.com/od/adptips2003/a/bltip1103_5.htm
可以在各大搜索引擎搜索微软新闻组的文章 "convert to VB .Net code - Highlight text using mshtml.IMarkupServices"
可以使用pasteHTML来替代处理。
个人认为没有很好的办法.重写也存在许多问题. 如:Private Sub Command1_Click() Dim doc, html As Object, strhtml As String With WebBrowser1 If Not .Busy Then Set doc = .Document Set html = doc.body.createtextrange() If Not IsNull(objhtml) Then strhtml = html.htmltext End If strhtml = Replace(strhtml, "学习", "<span style='background-color: #FFFF00'>学习</span>") With .Document .OPEN .write strhtml .Close End With End With End Sub
Private Sub Command1_Click()
With WebBrowser1.Document
.Open
.write Replace(X, "学习", "<span style='background-color: #FFFF00'>学习</span>")
.Close
End With
End SubPrivate Sub Form_Load()
X = "<body>好好学习,天天向上</body>"
WebBrowser1.Navigate2 ("about:blank")
Do While WebBrowser1.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
With WebBrowser1.Document
.Open
.write X
.Close
End With
End Sub
怎么样对浏览的网页操作呢?能不能在不刷新的情况下进行呢?
和Delphi的实现方法:HOW TO: Invoke the Find, View Source, and Options Dialog Boxes for the WebBrowser Control from Visual Basic .NEThttp://support.microsoft.com/kb/311288/EN-US/
How to call the Find dialog in WebBrowser
http://delphi.about.com/od/adptips2003/a/bltip1103_5.htm
"convert to VB .Net code - Highlight text using mshtml.IMarkupServices"
如:Private Sub Command1_Click()
Dim doc, html As Object, strhtml As String
With WebBrowser1
If Not .Busy Then
Set doc = .Document
Set html = doc.body.createtextrange()
If Not IsNull(objhtml) Then strhtml = html.htmltext
End If
strhtml = Replace(strhtml, "学习", "<span style='background-color: #FFFF00'>学习</span>")
With .Document
.OPEN
.write strhtml
.Close
End With
End With
End Sub