webBrowser 禁止屏蔽alert confirm open showModalDialog

 

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
        IHTMLWindow2 ihtmlWin = webBrowser1.Document.Window.DomWindow as IHTMLWindow2;
        //屏蔽alert
        string s = "var aaa=function(){return true;}\r\nwindow.alert = aaa;\r\nwindow.confirm = aaa;\r\nwindow.open = aaa;\r\nwindow.showModalDialog = aaa;";
        ihtmlWin.execScript(s, "javascript");
}

 

posted @ 2021-09-14 16:57  为乐而来  阅读(65)  评论(0编辑  收藏  举报