Highlight keywords

zhaozj2021-02-12  148

Highlight keywords

JavaScript code is as follows

function HightLight (nWord) {var oRange = document.body.createTextRange (); while (oRange.findText (nWord)) {oRange.pasteHTML ( "" oRange.text ""); Orange.MoveStart ('Character', 1);}}

If you use it in VB, improve it.

Public Sub HightLight2 (nKey $, nDoc As MSHTML.HTMLDocument, Optional beforeTag $ = "", Optional afterTag $ = "") On Error Resume NextDim tBody As MSHTML.HTMLBodyDim oRange As MSHTML.IHTMLTxtRange

If BeforeetaG = "" the beforeetaG = "" end ifif offrtag = "" "" ends "end if

Set tBody = nDoc.bodyIf 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 iFend IFEND SUB

If there are multiple frames in the page, then you need to do some work, I will not write.

LINGLL (Lingll2001@21cn.com) 2004-7-5

Supplement: Enumerates Frame You can refer to the following article http://www.mvps.org/emorcillo/vb6/inet/wbframe.shtml

.

Note: this Tip is based on the Microsoft Kb Article 196340 and Requieres the Oleelib.tlb Type Library.

Sub Enumframes (Byval WB AS Webbrowser) Dim PContainer As Oleelib.iolecontainerdim Penumerator As OleLib.ienumunknownDim Punk As OleLib.iunknownDim PBROWSER As Shdocvw.iWebBrowser2

转载请注明原文地址:https://www.9cbs.com/read-7205.html

New Post(0)