Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2006, 07:34 AM
Nader Nader is offline
Member
 
Join Date: Jul 2003
Posts: 39
Default Get Button Click Event in WebBrowser

I Browse the folowing HTML Page in WebBrowser Component:










I want Get every Tag Data of any button when click it. (i.e ShowMessage Button1 when click B1 and ... )

thanks.
________
Pornstar Cams

Last edited by Nader; 04-06-2011 at 08:25 PM.
Reply With Quote
  #2  
Old 04-16-2006, 08:23 AM
Nader Nader is offline
Member
 
Join Date: Jul 2003
Posts: 39
Default RE: Get Button Click Event in WebBrowser (Answer)

unit ct1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OleCtrls, SHDocVw_TLB,
MSHTML_TLB,
ExtCtrls, SHDocVw, Variants;

type
TBrowserClick = class( TComponent, IUnknown, IDispatch)
private
{ Private declarations }
FOnClick : TNotifyEvent;
FRefCount : integer;
function QueryInterface( const IID : TGUID; out Obj) : Integer; stdcall;
function _AddRef : Integer; stdcall;
function _Release : Integer; stdcall;
function Invoke( DispID : Integer; const IID : TGUID; LocaleID : Integer; Flags : Word; var Params; VarResult, ExcepInfo, ArgErr : Pointer) : HResult; stdcall;
protected
{ Protected declarations }
public
{ Public declarations }
property OnClick : TNotifyEvent read FOnClick write FOnClick;
published
{ Published declarations }
end;

type
TForm1 = class(TForm)
Panel1: TPanel;
WebBrowser1: TWebBrowser;
procedure FormCreate( Sender : TObject);
procedure WebBrowser1DocumentComplete( Sender : TObject; pDisp : IDispatch; var URL : OleVariant);
procedure BrowClick( Sender : TObject);
private
{ Private declarations }
BClick : TBrowserClick;
public
{ Public declarations }
end;


var
Form1: TForm1;

implementation

{$R *.DFM}

// TBrowserClick
function TBrowserClick.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if GetInterface(IID, Obj) then
Result := S_OK
else
Result := E_NOINTERFACE;
end;

function TBrowserClick._AddRef: Integer;
begin
Inc(FRefCount);
Result := FRefCount;
end;

function TBrowserClick._Release: Integer;
begin
Dec(FRefCount);
Result := FRefCount;
end;

function TBrowserClick.Invoke( DispID: Integer; const IID: TGUID; LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult;
begin
if Assigned( OnClick) then OnClick( Self);
Result := S_OK;
end;

///////////////////////////////////////////////////////////////////////////////

procedure TForm1.FormCreate( Sender: TObject);
begin
WebBrowser1.Navigate('D:\Documents and Settings\NN\My Documents\3.htm');
end;

procedure TForm1.WebBrowser1DocumentComplete( Sender : TObject; pDisp : IDispatch; var URL : OleVariant);
var
vDoc : OleVariant;
begin
if BClick <> nil then
BClick.Free;
BClick := TBrowserClick.Create( Application);
BClick.OnClick := BrowClick;
vDoc := WebBrowser1.Document;
vDoc.attachEvent( 'onclick', OleVariant( BClick as IDispatch));
end;

procedure TForm1.BrowClick( Sender : TObject);
var
vClick : IHTMLElement;
vTag, vID, vClass, vType, vName, vValue : WideString;
begin //
vClick := ( WebBrowser1.document as IHTMLDocument2).activeElement;
vTag := vClick.Get_tagName;
vID := vClick.Get_id;
vClass := vClick._className;
if vClick <> nil then
begin
if vClick.getAttribute( 'type', 0) <> null then
vType := vClick.getAttribute( 'type', 0);
if vClick.getAttribute( 'name', 0) <> null then
vName := vClick.getAttribute( 'name', 0);
if vClick.getAttribute( 'value', 0) <> null then
vValue := vClick.getAttribute( 'value', 0);
// etc ...
end;
// ShowMessage(vValue)

end;

end.

Is it Correct?
________
Jailbroken

Last edited by Nader; 04-06-2011 at 08:25 PM.
Reply With Quote
  #3  
Old 05-14-2006, 07:03 PM
nedubg nedubg is offline
Junior Member
 
Join Date: Dec 2005
Posts: 3
Default RE: Get Button Click Event in WebBrowser (Answer)

wow!! great code..how can you know url being send to server?

Thank you
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:23 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.