原文来自:http://blog.csdn.net/pengxuan/article/details/8684994
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
- <title>新建网页 1</title>
- <script>
- function aa(){
- alert("abc");
- }
- </script>
- </head>
- <body>
- <form method="POST" action="--WEBBOT-SELF--">
- <p><input type="button" value="按钮" name="B3" onclick="aa()"></p>
- </form>
- </body>
- </html>
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML_TLB;
- type
- TForm1 = class(TForm)
- WebBrowser1: TWebBrowser;
- Button1: TButton;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- uses Math;
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- WebBrowser1.Navigate('c:\index.htm');
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- var b:IHTMLElement;
- begin
- b:=(WebBrowser1.Document as IHTMLDocument3).getElementById('B3');
- if b=nil then exit;//这里判断网页中是不是找到了这个按钮,如果换成B4就不能执行下面的代码了
- b.click;
- end;
- end.