Delphi_判断Webbrowser打开的网页组件是否存在?

原文来自:http://blog.csdn.net/pengxuan/article/details/8684994


  1. <html>  
  2.   
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  5. <title>新建网页 1</title>  
  6. <script>  
  7. function aa(){  
  8.   alert("abc");  
  9. }  
  10. </script>  
  11. </head>  
  12.   
  13. <body>  
  14.   
  15. <form method="POST" action="--WEBBOT-SELF--">  
  16.     <p><input type="button" value="按钮" name="B3" onclick="aa()"></p>  
  17. </form>  
  18.   
  19. </body>  
  20.   
  21. </html> 

  1. unit Unit1;  
  2.   
  3. interface  
  4.   
  5. uses  
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  
  7.   Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML_TLB;  
  8.   
  9. type  
  10.   TForm1 = class(TForm)  
  11.     WebBrowser1: TWebBrowser;  
  12.     Button1: TButton;  
  13.     procedure FormCreate(Sender: TObject);  
  14.     procedure Button1Click(Sender: TObject);  
  15.   private  
  16.     { Private declarations }  
  17.   public  
  18.     { Public declarations }  
  19.   end;  
  20.   
  21. var  
  22.   Form1: TForm1;  
  23.   
  24. implementation  
  25.   
  26. uses Math;  
  27.   
  28. {$R *.dfm}  
  29.   
  30. procedure TForm1.FormCreate(Sender: TObject);  
  31. begin  
  32. WebBrowser1.Navigate('c:\index.htm');  
  33. end;  
  34.   
  35. procedure TForm1.Button1Click(Sender: TObject);  
  36. var b:IHTMLElement;  
  37. begin  
  38.   b:=(WebBrowser1.Document as IHTMLDocument3).getElementById('B3');  
  39.   if b=nil then exit;//这里判断网页中是不是找到了这个按钮,如果换成B4就不能执行下面的代码了  
  40.   b.click;  
  41. end;  
  42.   
  43. end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值