Search code examples
htmldelphieventsbrowseronkeypress

How to call onkeypress event in a html page (Delphi)


How can i call onkeypress event of a textarea control in a html page using WebBrowser?


Solution

  • This is a way with late binding:

    procedure TBrowserPageIE.Test;
    var
      doc : OleVariant;
      el  : OleVariant;
      v   : OleVariant;
    begin
      if FBrowser.Document <> nil then begin
        doc := FBrowser.Document;
        el := doc.getElementById('myTextArea');
        el.FireEvent('onkeypress', v);
      end;
    end;
    

    Please add some code for nil/exception handling.