This is covered in the following article by Peter Johnson, How to make a TWebBrowser become the active control when clicked.
To summarise heavily, add this OnCommandStateChange event:
procedure TWebBrowserFrame.CommandStateChange(Sender: TObject; Command: Integer; Enable: WordBool); var Doc: IHTMLDocument2; // document object Sel: IHTMLSelectionObject; // current selection begin // Check we have a valid web browser triggering this event if not Assigned(Sender) or not (Sender is TWebBrowser) then Exit; // Check we have required command if TOleEnum(Command) <> CSC_UPDATECOMMANDS then Exit; // Get ref to document object and check not nil Doc := Browser.Document as IHTMLDocument2; if not Assigned(Doc) then Exit; // Get ref to current selection Sel := Doc.selection as IHTMLSelectionObject; // If selection is of correct type then we have a mouse click if Assigned(Sel) and (Sel.type_ = 'Text') then begin // Make the web browser the form's active control (Sender as TWebBrowser).SetFocus; Doc.parentWindow.focus; end; end;
There is a lot more detail in the article, please do make sure you read it all.