Am having a awful time trying to get this to work I googled it and even asked few friends about it, but it seams it more difficult than I expected it to be.

basicly what am trying to do is capture if or when a user clicks on a button within a html page as follows:

<button type="button">Click Me!</button>

then for my program to reacte by showing a dialog such as good old Hello World message, but it seamns to be very difficult indeed and when I googled there is help on how to make a normal TButton press a button with in the html file it self but this is not really what I need can anyone help me at all?

Thanks

Start a new project.
Add a status bar and set SimplePanel TRUE.
Add a TWebBrowser (and set Align alClient).
Add this for the form's onCreate event handler:

procedure TForm2.FormCreate(Sender: TObject);
begin
  Application.OnMessage := MyMessages;
  wb1.Navigate('https://www.google.com/');  // Or whatever site you want
end;

Add a private procedure to the form:

procedure MyMessages(var Msg: TMsg; var Handled: Boolean);

Implement that procedure like this:

procedure TForm2.MyMessages(var Msg: TMsg; var Handled: Boolean);
var
  X, Y: Integer;
  document,
  E: OleVariant;
begin
  if (Msg.message = WM_LBUTTONDOWN) and IsDialogMessage(wb1.Handle, Msg) then
  begin
    X := LOWORD(Msg.lParam);
    Y := HIWORD(Msg.lParam);
    document := wb1.Document;
    E := document.elementFromPoint(X, Y);
    sbar1.SimpleText := 'You clicked on:' + E.outerHTML;
  end;
  Handled := False;
end;

Run the app and click on a button; the status bar shows something like:

'You clicked on: <input name="btnI" aria-label="I'm Feeling Lucky" type="submit" value="I'm Feeling Lucky" jsaction="sf.lck">'

You could check that text and call whatever routine you like based on the content.
Would this help you do what you want?

Oh, and if you don't want the web page to react to the click in the normal way (so clicking the button only runs your procedure without actually clicking the button) you should set Handled to TRUE.

Thanks mate

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.