首页  编辑  

查找并且高亮文本

Tags: /超级猛料/OS.操作系统/IE.扩展/TWebBrowser/页面内容/   Date Created:

find and highlight text in TWebBrowser?

{....}

 private

   procedure SearchAndHighlightText(aText: string);

   

{....}

procedure TForm1.SearchAndHighlightText(aText: string);

var

 i: Integer;

begin

 for i := 0 to WebBrowser1.OleObject.Document.All.Length - 1 do

 begin

   if Pos(aText, WebBrowser1.OleObject.Document.All.Item(i).InnerText) <> 0 then

   begin

     WebBrowser1.OleObject.Document.All.Item(i).Style.Color := '#FFFF00';

     WebBrowser1.OleObject.Document.All.Item(i).ScrollIntoView(True);

   end;

 end;

end;

procedure TForm1.Button1Click(Sender: TObject);

begin

 SearchAndHighlightText('some text...');

end;