C# WebBrowser 禁止WebBrowser控制元件彈出對話方塊
阿新 • • 發佈:2019-02-01
一、遮蔽alert、confirm、showModalDialog原始碼:
例1、先引用COM組建mshtml;
引用名稱空間mshtml:
using mshtml;
然後處理WebBrowser控制元件的Navigated事件,程式碼如下:
- privatevoid 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");
- }