如何用程序关闭WebBrowser中的网页(javascript)弹出的对话框 本帖最后由 suleil1 于 2010-04-14 16:15:18 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用AutoHotKey,就是热键,只要弹出这个窗体就自动把它点掉 以前lihuasoft 曾经发过测试代码,我给你贴出来: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页面装载完毕后开启Timerend;procedure TForm1.FormCreate(Sender: TObject);begin Self.Timer1.Enabled := False; Self.Timer1.Interval:= 100;end;'这是C:\Documents and Settings\jiaotongju\桌面\test2\test.htm的内容<html><head><title>test</title></head><body><form method="POST" action=""><p><input type="button" value="按钮" name="B1" onclick="alert('关掉我')"></p></form></body></html> 试试webBrowser1.ScriptErrorsSuppressed = true; if(confirm("确定要删除")) alert("我确定后的代码操作");//删除操作else return ; 在弹出对话框后可否发送一个enter呢?嘿嘿,没弄过,纯属瞎想 在弹出对话框后可否发送一个enter呢?嘿嘿,没弄过,纯属瞎想 如果屏蔽JS,那么连框都不弹,我就不能提交了。还有,输入Enter键也不行SendKey.send("enter")这句根本没执行就卡住了,线程已经阻塞了。还有4楼的哥们,你给的代码好像不是C#的吧 新建个线程,FindWindow查找弹出的对话框的句柄,然后发送消息WM_CLOSE关闭 http://topic.csdn.net/u/20080516/13/6d926aad-3a9d-44ec-a25b-df2e4bdac208.html参考这个用FindWindowEx来找到你这个对话框的句柄,然后SendMessage发送消息 using mshtml; using SHDocVw; private void Form1_Load(object sender, EventArgs e) { this.webBrowser1.Navigate("http://localhost:28512/test/Default.aspx"); SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser; wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); } void wb_NavigateComplete2(object pDisp, ref object URL) { mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHTMLDocument2; doc.parentWindow.execScript("function alert(str){return ''}", "javascript"); } 求救!如何csv逐行输出每行value到Listbox 为什么需要这个方法? 关于继承 隐藏实例成员(无virtual修饰) c# 根据IP查询计算机硬件信息! 讨几道关于接口应用的练习题目! C# 如何调用DLL函数返回的结构体指针 再次提问ROW_NUMBER函数分页 谁给我讲下 Label控件中 的Text的属性是什么原理做的? 在c#中如何改变Excel中的边框的颜色???? 问一个关于ArrayList 的问题(急) webservices如何实现接口 C#代码求改错
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;
'这是C:\Documents and Settings\jiaotongju\桌面\test2\test.htm的内容
<html><head>
<title>test</title>
</head><body><form method="POST" action="">
<p><input type="button" value="按钮" name="B1" onclick="alert('关掉我')"></p>
</form></body></html>
webBrowser1.ScriptErrorsSuppressed = true;
alert("我确定后的代码操作");//删除操作
else
return ;
嘿嘿,没弄过,纯属瞎想
嘿嘿,没弄过,纯属瞎想
还有,输入Enter键也不行SendKey.send("enter")这句根本没执行就卡住了,线程已经阻塞了。
还有4楼的哥们,你给的代码好像不是C#的吧
http://topic.csdn.net/u/20080516/13/6d926aad-3a9d-44ec-a25b-df2e4bdac208.html参考这个用FindWindowEx来找到你这个对话框的句柄,然后SendMessage发送消息
using SHDocVw;
private void Form1_Load(object sender, EventArgs e)
{
this.webBrowser1.Navigate("http://localhost:28512/test/Default.aspx");
SHDocVw.WebBrowser wb = this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser;
wb.NavigateComplete2 += new SHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(wb_NavigateComplete2); } void wb_NavigateComplete2(object pDisp, ref object URL)
{
mshtml.IHTMLDocument2 doc = (this.webBrowser1.ActiveXInstance as SHDocVw.WebBrowser).Document as mshtml.IHTMLDocument2;
doc.parentWindow.execScript("function alert(str){return ''}", "javascript");
}