我正在使用此代码从 IHTMLDocument2 获取所有链接:
procedure DoDocumentComplete(const pDisp: IDispatch; var URL: OleVariant);
var
Document:IHTMLDocument2;
Body:IHTMLElement;
Links:IHTMLElementCollection;
i:integer;
tmp:IHTMLElement;
begin
try
Document := (pDisp as IWebbrowser2).Document AS IHTMLDocument2;
Body := Document.body;
Links := Document.links;
for i := 0 to (Links.length-1) do
begin
tmp := (Links.item(i, 0) as IHTMLElement);
//tmp.onclick := HOW SHOULD I ADD THE CALLBACK HERE?
//ShowMessage(tmp.innerText);
end;
except
on E : Exception do
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
end;
end;
如何将函数/过程附加到 .onclick 以执行简单的任务,例如在单击链接时显示带有锚文本的警报?