如何用程序关闭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"); } C#中ihtmldocument2如何获取页面内容 向各位请教一下,C# 如何获取AIX的CPU使用率...[标题要长....] 请问下有没有人用过下载资源里面的QQ IM 聊天 C# .net TCP 網絡編程? 计算机术语 抛 如何判断按了回车键? 水晶报表如何打印表格? 怎样判断某个dll是否已被Assembly.LoadFrom(),不给再次调用. 为什么在Richtextbox中粘贴的图片,保存了就看不到了? 没有原代码。可否更改装配件的.net 依赖版本么? 自己搞了百度网盘搜索引擎,欢迎大家来吐糟 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");
}