怎么样才可以在WebBrowser的内容中查找指定的字符串并使其高亮显示呢?

eeb 2005-09-24 12:40:07
怎么样才可以在WebBrowser的内容中查找指定的字符串并使其高亮显示呢?

比如把网页中含有“学习”两字变换为<span style="background-color: #FFFF00">学习</span>
就好象百度中网页快照中的查找关键字高亮显示。
...全文
434 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2005-09-25
  • 打赏
  • 举报
回复
个人认为没有很好的办法.重写也存在许多问题.
如:

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
luckit 2005-09-25
  • 打赏
  • 举报
回复
可以使用pasteHTML来替代处理。
蒋晟 2005-09-24
  • 打赏
  • 举报
回复
可以在各大搜索引擎搜索微软新闻组的文章
"convert to VB .Net code - Highlight text using mshtml.IMarkupServices"
lingll 2005-09-24
  • 打赏
  • 举报
回复
http://www.csdn.net/Develop/read_article.asp?id=30263
TechnoFantasy 2005-09-24
  • 打赏
  • 举报
回复
因为Find方法需要通过IOLECommandTarget接口来实现,通过VB实现很难,下面是VB.NET
和Delphi的实现方法:

HOW TO: Invoke the Find, View Source, and Options Dialog Boxes for the WebBrowser Control from Visual Basic .NET

http://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
eeb 2005-09-24
  • 打赏
  • 举报
回复
northwolves(狼行天下) :
怎么样对浏览的网页操作呢?能不能在不刷新的情况下进行呢?
northwolves 2005-09-24
  • 打赏
  • 举报
回复
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 Sub

Private 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

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧