关于用WebBrowser1在网页中的点击问题(200分求助) ( 积分: 200 )

W

wang_hn

Unregistered / Unconfirmed
GUEST, unregistred user!
有这样的一网页段源代码:
<P align=center><STRONG>
<SPAN style=&quot;CURSOR: hand&quot; onclick=Answer()>继续答题</SPAN> <SPAN style=&quot;CURSOR: hand&quot; onclick=&quot;register('_self')&quot;>完成</SPAN></STRONG></P></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD>

我用的WebBrowser控件,请问怎么才能点击到‘继续答题’或‘完成’并能执行到onclick事件。?????
不要采用模拟鼠标点击。
 

风铃夜思雨

Unregistered / Unconfirmed
GUEST, unregistred user!
var HTMLDocument: IHTMLDocument2;
begin
HTMLDocument := IHTMLDocument2(WebBrowser1.Document);
HTMLDocument.parentWindow.execScript('Answer()', 'javascript');
HTMLDocument.parentWindow.execScript('register(''_self'')&quot;', 'javascript');
end;
 
L

lisongmagic

Unregistered / Unconfirmed
GUEST, unregistred user!
也就是相应网页上的按钮了;
以前下过一个例子,关于webbrower的
<area shape=&quot;rect&quot; coords=&quot;629,430,747,465&quot; href=&quot;Email_&quot; alt=&quot;发邮件&quot; >
<area shape=&quot;rect&quot; coords=&quot;465,243,608,362&quot; href=&quot;photo2_&quot; alt=&quot;照片二&quot; >
<area shape=&quot;rect&quot; coords=&quot;243,235,383,368&quot; href=&quot;photo1_&quot; alt=&quot;照片一&quot; >
<area shape=&quot;rect&quot; coords=&quot;20,323,138,358&quot; href=&quot;button4_&quot; alt=&quot;按这里退出程序&quot; >
<area shape=&quot;rect&quot; coords=&quot;20,267,138,302&quot; href=&quot;button3_&quot; alt=&quot;这是按钮三&quot; >
<area shape=&quot;rect&quot; coords=&quot;24,217,142,252&quot; href=&quot;button2_&quot; alt=&quot;这是按钮二&quot; >
<area shape=&quot;rect&quot; coords=&quot;24,166,142,201&quot; href=&quot;button1_&quot; alt=&quot;这是按钮一&quot; >

delphi中的关键代码:
procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
If Pos('button1_', URL)>0 Then
Begin
ShowMessage('你选择了按钮一!');
Cancel:=True;
End;
If Pos('button2_', URL)>0 Then
Begin
ShowMessage('你选择了按钮二!');
Cancel:=True;
End;
If Pos('button3_', URL)>0 Then
Begin
ShowMessage('你选择了按钮三!');
Cancel:=True;
End;
If Pos('button4_', URL)>0 Then close;

If Pos('photo1_', URL)>0 Then
Begin
ShowMessage('你选择了图片一!');
Cancel:=True;
End;
If Pos('photo2_', URL)>0 Then
Begin
ShowMessage('你选择了图片二!');
Cancel:=True;
End;
If Pos('Email_', URL)>0 Then
Begin
ShowMessage('发邮件!');
Cancel:=True;
End;
end;
 
W

wang_hn

Unregistered / Unconfirmed
GUEST, unregistred user!
看了风铃夜思雨,的答案我去试试看。
 
W

wang_hn

Unregistered / Unconfirmed
GUEST, unregistred user!
风铃夜思雨, 的方法不错,验证通过了。我结贴了。
lisongmagic 没有看清我的问题,并且方法也不对。
 

Similar threads

S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部