【发布时间】:2017-02-08 09:56:14
【问题描述】:
DesignMode 开启时如何检测 TWebBrowser 中点击了哪个 HTML 元素(标签)?
问题:
当 DesignMode 开启时:
- Document_OnMouseOver 永远不会执行。
- 文档从未完成加载。
- 单击链接时未调用BeforeNavigate2。
更新:
我需要的是 IHTMLTxtRange (我认为)。当我双击链接/单词时,它会起作用。但是当没有选择文本/链接时,我不知道如何在插入符号下获取标签。
procedure TForm1.getRange;
var
Sel: IHTMLSelectionObject;
Range: IHTMLTxtRange;
Doc: IHTMLDocument2;
begin
Doc := EmbeddedWB.Doc2;
if Assigned(Doc) then
begin
Sel := Doc.selection;
if Assigned(Sel) then
begin
if (Sel.type_ = 'None') or (Sel.type_ = 'Text') then
begin
Range := Sel.createRange as IHTMLTxtRange;
Range.expand('word');
Memo.Text:=
Range.htmlText + crlf + // full tag
Range.text; // only text
end;
end;
end;
【问题讨论】:
-
我不认为活动元素是你想要的。当然你需要获取坐标(客户端坐标),然后调用
IHtmlDocument2.elementFromPoint。 -
可以在OnBeforeNavigate事件中获取链接
-
嗨,大卫。我昨天已经试过了,但没有运气。我只得到“身体”。这是代码:stackoverflow.com/questions/42110608/…
-
@DarkPresidentOfAmerica:这对你有帮助吗?
标签: html delphi onclick delphi-xe7 twebbrowser