Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html TWebBrowser-检测插入符号下的标记_Html_Delphi_Internet Explorer_Delphi Xe7_Twebbrowser - Fatal编程技术网

Html TWebBrowser-检测插入符号下的标记

Html TWebBrowser-检测插入符号下的标记,html,delphi,internet-explorer,delphi-xe7,twebbrowser,Html,Delphi,Internet Explorer,Delphi Xe7,Twebbrowser,我想检测哪个HTML标记(更确切地说是超链接)是插入符号 procedure THTMLEdit.ShowTag; var CursorPos: TPoint; HtmlElement: IHTMLElement; iHTMLDoc: IHtmlDocument2; begin if Supports(wbBrowser.Document, IHtmlDocument2, iHTMLDoc) then begin if GetcaretPos(CursorPo

我想检测哪个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;
程序THTMLEdit.ShowTag;
变量
光标:t点;
HtmlElement:IHTMLElement;
iHTMLDoc:IHtmlDocument2;
开始
如果支持(wbBrowser.Document、IHtmlDocument2、iHTMLDoc),则
开始
如果GetcaretPos(CursorPos),则
开始
CursorPos:=wbBrowser.screentoclient(CursorPos);
HtmlElement:=iHTMLDoc.ElementFromPoint(CursorPos.X,CursorPos.Y);//我这里需要键盘插入符号,而不是鼠标光标
如果HtmlElement为零
然后label1.Caption:=HtmlElement.tagName;
结束;
结束;
结束;
注:
TWebBrowser处于设计模式(设计模式:='On')。
TWebBrowser在设计时以自己的形式出现,但在运行时以另一种形式(在面板中)重新设置父对象

更新:
我需要的是IHTMLTxtRange(我想)。当我双击一个链接/单词时,它会起作用。但我不知道在未选择文本/链接时如何获取插入符号下的标记。

GetcaretPos(CursorPos)返回客户端(相对)坐标(请参阅)


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

您可以看看我对这个问题的回答:,特别是
t对于m1.AnEvent
这样模糊的信息很难帮助您。要将标记放在光标下吗?但是您可以调用
GetCaretPos
。您要光标还是插入符号?在你的另一个问题中,你显然只对
链接感兴趣。你能不能慢一点,花点时间,告诉我们你实际上在做什么。用一系列不精确和不清楚的问题向我们发送垃圾邮件是没有建设性的,这表明了阻碍你前进的混乱思维。[通常]当你点击一个编辑器时,光标和插入符号会出现在同一个位置。但你是对的,我是模棱两可的。我想把标签放在插入符号下。@DarkPresidentOfAmerica,你可以用MartynA的答案处理
onmouseup
事件。然后类似于:
rg:=Doc.selection.createRange;rg.崩塌;el:=rg.parentElement在什么情况下称为ShowTag?它几乎可以工作。问题:它显示了以前单击的标记。例如,如果我单击一个

标记,然后单击一个链接(),它将显示

。所以,为了工作,我必须点击链接两次!