How to detect which HTML element (tag) was clicked in TWebBrowser when DesignMode is ON?
The problem:
When DesignMode is on:
- Document_OnMouseOver never executes.
- The document never completes loading.
- BeforeNavigate2 is not called when I click a link.
Update:
The thing that I need is IHTMLTxtRange (I think). It works when I double click a link/word. But I don't know how to get the tag under caret when no text/link is selected.
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;