TWebBrowser - 检测插入符号下的标签

TWebBrowser - Detecting the tag under caret

我想检测哪个 HTML 标记(更准确地说是超链接)是插入符。

procedure THTMLEdit.ShowTag;     
var
  CursorPos: TPoint;
  HtmlElement: IHTMLElement;
  iHTMLDoc: IHtmlDocument2;
begin
 if Supports(wbBrowser.Document, IHtmlDocument2, iHTMLDoc) then
  begin
    if GetcaretPos(CursorPos) then
    begin
      CursorPos := wbBrowser.screentoclient(CursorPos);
      HtmlElement := iHTMLDoc.ElementFromPoint(CursorPos.X, CursorPos.Y);  // I NEED KEYBOARD CARET HERE, NOT MOUSE CURSOR
      if HtmlElement <> NIL
      then label1.Caption:= HtmlElement.tagName;
    end;
  end;
end;

备注:
TWebBrowser 处于 DesignMode ( DesignMode := 'On' ).
TWebBrowser 在设计时以其自己的形式出现,但在运行时以另一种形式(在面板中)重新设置父级。

更新:
我需要的是 IHTMLTxtRange(我认为)。当我双击 link/word 时它起作用了。但是当没有选择 text/link 时,我不知道如何在插入符号下获取标签。

GetcaretPos(CursorPos) returns 客户端(相对)坐标(参见 GetCaretPos function

删除 wbBrowser.screentoclient(CursorPos) 它应该可以正常工作。我已经用你上面的代码示例进行了测试