主题:水题,C# 在webBrowser里加脚本
目的是禁止webBrowser的alert和confirm提示,在VS2005调试环境下成功执行,编译后程序无效。
知道解决办法的指点一下,谢谢!~
[b]代码如下:[/b]
HtmlDocument doc = webBrowser1.Document.Window.Frames[0].Frames[1].Document;
mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)doc.Window.DomWindow;
string s = @"function confirm() {";
s += @"return true;";
s += @"}";
s += @"function alert() {}";
win.execScript(s, "javascript");
//(webBrowser1.Document.Window.DomWindow as mshtml.IHTMLWindow2).execScript(s, "javascript");
//for (int i = 0; i < webBrowser1.Document.Window.Frames.Count; i++)
//{
// (webBrowser1.Document.Window.Frames[i].Document.Window.DomWindow as mshtml.IHTMLWindow2).execScript(s, "javascript");
// for (int j = 0; j < webBrowser1.Document.Window.Frames[i].Frames.Count; j++)
// {
// (webBrowser1.Document.Window.Frames[i].Frames[j].Document.Window.DomWindow as mshtml.IHTMLWindow2).execScript(s, "javascript");
// }
//}