WPF WebBrowser屏蔽弹出alert ,confirm ,prompt ,showModalDialog() ,window.open()


添加Microsoft.mshtml.dll,然后写如下代码

void
browser_Navigated(object sender, NavigationEventArgs e) { txtUrl.Text = e.Uri.ToString(); WebBrowser wbWebBrowser = (WebBrowser)sender; StringBuilder msgb = new StringBuilder(); msgb.AppendLine("function alert(){return;}"); msgb.AppendLine("function confirm(){return;}"); msgb.AppendLine("function showModalDialog(){return;}"); msgb.AppendLine("function window.open(){return;}"); msgb.AppendLine("function prompt(){return;}"); string strJS = msgb.ToString(); IHTMLWindow2 win = (IHTMLWindow2)(wbWebBrowser.Document as IHTMLDocument2).parentWindow; win.execScript(strJS, "Javascript"); win = null; }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM