屏蔽alert、confirm、showModalDialog源代码:
lert,confirm函数:
IHTMLWindow2 win = (IHTMLWindow2)hd.Window.DomWindow;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";
s += @"function alert() {}";
win.execScript(s, "javascript");
OK ,大功告成,我们可以继续我们正常的操作拉,比如填写表单并提交:
hd.All["username"].SetAttribute("value","username");
hd.All["password"].SetAttribute("value","password");
hd.All["buttom"].InvokeMember("click");
在CSDN上有类似的问题,参见http://topic.csdn.net/u/20080313/00/5e2add09-6103-405f-8f6b-6bbb220e9cfd.html
function CallBackProc(H, HMainForm: hwnd): Boolean; stdcall;
var
hChild : hwnd;
begin
Result := True;
if GetParent(H) = HMainForm then begin //可以在这里进一步判断类名,以免关掉其他弹出窗口
hChild := FindWindowEx(H, 0, PChar('Button'), PChar('确定'));
if hChild > 0 then SendMessage(hChild, BM_Click, 0, 0);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
EnumWindows(@CallBackProc, Self.Handle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Self.WebBrowser1.Navigate('C:\Documents and Settings\jiaotongju\桌面\test2\test.htm');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Self.Timer1.Enabled := True;//Web页面装载完毕后开启Timer
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Self.Timer1.Enabled := False;
Self.Timer1.Interval:= 100;
end;
你可以在VB程序中判断,当新网页打开后,主动退出程序。
在触发navigate事件后, 设置timer检查有没有alert弹出,有的话关闭alert,或者在alert里找到类似OK\确定的按钮然后发送click
没用过