WPF WebBrowser屏蔽弹出alert ,confirm ,prompt ,showModalDialog() ,window.open()
添加Microsoft.mshtml.dll,然后写如下代码

void browser_Navigated(object sender, NavigationEventArgs e) {
txtUrl.Text = e.Uri.ToString();//显示当前的url
WebBrowser wbWebBrowser = (WebBrowser)sender;
StringBuilder msgb = new StringBuilder();
msgb.AppendLine("function alert(){return;}");
msgb.AppendLine("function confirm(){return;}");;
msgb.AppendLine("function window.open(){return;}");
msgb.AppendLine("function prompt(){return;}"); IHTMLWindow2 win = (IHTMLWindow2)(wbWebBrowser.Document as IHTMLDocument2).parentWindow;
win.execScript(msgb.ToString(), "Javascript");
win = null;
}
05-07 12:43