高亮网页中的关键字
来源:互联网 发布:怎样配置java运行环境 编辑:程序博客网 时间:2024/05/17 04:10
高亮网页中的关键字
javascript的代码如下
function HightLight(nWord)
{
var oRange = document.body.createTextRange();
while(oRange.findText(nWord))
{
oRange.pasteHTML("<span style='background-color:yellow'>" + oRange.text + "</span>");
oRange.moveStart('character',1);
}
}
如果在vb中使用,改进一下,
Public Sub HightLight2(nKey$, nDoc As MSHTML.HTMLDocument, Optional beforeTag$ = "", Optional afterTag$ = "")
On Error Resume Next
Dim tBody As MSHTML.HTMLBody
Dim oRange As MSHTML.IHTMLTxtRange
If beforeTag = "" Then
beforeTag = "<span style='background-color:yellow'>"
End If
If afterTag = "" Then
afterTag = "</span>"
End If
Set tBody = nDoc.body
If Not tBody Is Nothing Then
Set oRange = tBody.createTextRange
If Not oRange Is Nothing Then
While oRange.FindText(nKey)
Call oRange.pasteHTML(beforeTag & oRange.Text & afterTag)
Call oRange.MoveStart("character", 1)
Wend
End If
End If
End Sub
如果页面中有多个frame,那么还需要做些工作,我就不写了.
lingll (lingll2001@21cn.com)
2004-7-5
补充:
枚举页面中的frame可以参考下面的文章
http://www.mvps.org/emorcillo/vb6/inet/wbframe.shtml
Getting the IWebBrowser2 interface for each HTML frame
This code enumerates the frames of a HTML page loaded in the WebBrowser control to get they IWebBrowser2 interface.
Note: This tip is based on the Microsoft KB article 196340 and requieres the OLELIB.TLB type library.
Sub EnumFrames(ByVal wb As WebBrowser)
Dim pContainer As olelib.IOleContainer
Dim pEnumerator As olelib.IEnumUnknown
Dim pUnk As olelib.IUnknown
Dim pBrowser As SHDocVw.IWebBrowser2
Set pContainer = wb.Object.Document
' Get an enumerator for the frames
If pContainer.EnumObjects(OLECONTF_EMBEDDINGS, pEnumerator) = 0 Then
Set pContainer = Nothing
' Enumerate and refresh all the frames
Do While pEnumerator.Next(1, pUnk) = 0
On Error Resume Next
' Clear errors
Err.Clear
' Get the IWebBrowser2 interface
Set pBrowser = pUnk
If Err.Number = 0 Then
Debug.Print "Frame: " & pBrowser.LocationURL
End If
Loop
Set pEnumerator = Nothing
End If
End Sub
- 高亮网页中的关键字
- 高亮网页中的关键字
- 高亮网页中的关键字
- 高亮注释中的关键字
- iOS中的关键字高亮
- 高亮显示VC++开发环境中的自定义关键字
- mac系统下vi编辑器中的关键字高亮设置
- 一段文字中的几个关键字显示高亮
- Android 高亮变色显示文本中的关键字
- 使用javascript将页面中的关键字高亮显示
- lucene高亮关键字
- lucene 关键字高亮
- ASP高亮关键字
- 高亮显示关键字
- 高亮显示关键字
- Java高亮关键字
- 高亮显示关键字
- 高亮显示关键字
- 利用C#进行AutoCAD的二次开发
- Does AutoCAD ActiveX work with Microsoft’s J++ Java or Borland’s Delphi environment?
- 类的研究
- C++ Builder开发AutoCAD应用程序的方法
- 如何在Delphi中调用Matlab(ActiveX)?
- 高亮网页中的关键字
- ★@累@★
- 美数学爱好者发现已知最大素数
- c#-vb.net转换工具(转载)
- 对主流技术的分析和总结
- Delphi下的COM编程技术简介
- 封面文章:寻找技术中国——渴望不再被扼住喉咙!
- Delphi中读写COM口
- 以地籍库为例介绍AutoCAD数据库连接