如何解决webBrowser新开页面问题?
问题:
页面中的链接target=_blank 或 window.open()引起的页面新开,直接就用ie打开了,我想就在当前webBrowser中显示新页。
如何解决?
令,如果是ie新开,新开页面会丢失Session吗?
谢谢!
分不够,再加!在线等!!!
------回答---------
------回答(30分)---------
响应webbrowser的Navigating事件
截取e.Url,然后将e.Cancel设为true以取消操作,然后将webbrowser直接导航至Url
------回答(20分)---------
- C# code
private void webBrowser1_NewWindow(object sender, CancelEventArgs e) { e.Cancel = true; //取消使用系统的IE打开超链接 form2.webBrowser1.Navigate((sender as WebBrowser).Document.ActiveElement.GetAttribute("href"));//form2是自己设计的含有webBrowser1控件的窗体,参数就是你点击的超链接的字符串URL }
------回答(25分)---------
在WebBrowser控件中阻止alert,confirm对话框
//禁用目标window的confirm、alert等对话框。
private void disableConfirm()
{
HtmlDocument doc = webBrowser1.Document.Window.Frames["mainFrame"].Document;
//框架结构中,必须正确的指定目标框架
IHTMLWindow2 win = (IHTMLWindow2)doc.Window.DomWindow;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";
s += @"function alert() {}";
win.execScript(s, "
javascript");
}
这个方法是自己写confirm alert方法把原文档的方法替换掉的方式
------回答(25分)---------
- C# code
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e){ IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow; string s = "window.alert = null;\r\nwindow.confirm = null;\r\nwindow.open = null;\r\nwindow.showModalDialog = null;"; win.execScript(s, "
javascript");}
------回答---------
------回答(30分)---------
响应webbrowser的Navigating事件
截取e.Url,然后将e.Cancel设为true以取消操作,然后将webbrowser直接导航至Url
------回答(20分)---------
- C# code
private void webBrowser1_NewWindow(object sender, CancelEventArgs e) { e.Cancel = true; //取消使用系统的IE打开超链接 form2.webBrowser1.Navigate((sender as WebBrowser).Document.ActiveElement.GetAttribute("href"));//form2是自己设计的含有webBrowser1控件的窗体,参数就是你点击的超链接的字符串URL }
------回答(25分)---------
在WebBrowser控件中阻止alert,confirm对话框
//禁用目标window的confirm、alert等对话框。
private void disableConfirm()
{
HtmlDocument doc = webBrowser1.Document.Window.Frames["mainFrame"].Document;
//框架结构中,必须正确的指定目标框架
IHTMLWindow2 win = (IHTMLWindow2)doc.Window.DomWindow;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";
s += @"function alert() {}";
win.execScript(s, "javascript");
}
这个方法是自己写confirm alert方法把原文档的方法替换掉的方式
------回答(25分)---------
- C# code
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e){ IHTMLWindow2 win = (IHTMLWindow2)webBrowser1.Document.Window.DomWindow; string s = "window.alert = null;\r\nwindow.confirm = null;\r\nwindow.open = null;\r\nwindow.showModalDialog = null;"; win.execScript(s, "javascript");}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。