这里有个组件可以很容易做到
TWebEvent
相关下载: http://new.playicq.com/dispdocnew.php?id=5018
下面是个例子,在当前窗口的标题中显示鼠标在WebBrowser控件中的位置
你自己可以添加任何事件,可以捕捉大多数html标记的事件
最新的组件源码可以向我索取
object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -12
Font.Name = '宋体'
Font.Style = []
OldCreateOrder = False
Position = poScreenCenter
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 12
object WebBrowser1: TWebBrowser
Left = 16
Top = 8
Width = 441
Height = 225
TabOrder = 0
OnDocumentComplete = WebBrowser1DocumentComplete
ControlData = {
4C000000942D0000411700000000000000000000000000000000000000000000
000000004C000000000000000000000001000000E0D057007335CF11AE690800
2B2E126208000000000000004C0000000114020000000000C000000000000046
8000000000000000000000000000000000000000000000000000000000000000
00000000000000000100000000000000000000000000000000000000}
end
object WebEvent1: TWebEvent
OnEvent = WebEvent1Event
WebEvents = <>
Left = 16
Top = 240
end
end
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, WebEvent, MsHtml;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
WebEvent1: TWebEvent;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure WebEvent1Event(Sender: TWebBrowser; event,
SrcElement: OleVariant);
private
{ Private declarations }
public
{ Public declarations }
end;
var
form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.playicq.com');
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
WebEvent1.EvtSource := WebBrowser1;
WebEvent1.EventsToFire := 'onmousemove';
WebEvent1.StandardTags := 'document';
WebEvent1.AttachEvents;
end;
procedure TForm1.WebEvent1Event(Sender: TWebBrowser; event,
SrcElement: OleVariant);
begin
Caption := IntToStr(event.x) + ',' + IntToStr(event.y);
end;
end.