添加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;
}