日期:2014-05-20  浏览次数:20413 次

webbrowse控件的问题.急!!!!
winform环境,webbrowse控件能不能屏蔽掉alert弹出来的提示框?
急呀.........

------解决方案--------------------
//项目中添加Micrsoft.mshtml引用
using mshtml;

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
vDocument.parentWindow.execScript(
"function alert(str){return;} ", "javaScript ");
}

//frame结构

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;
foreach (IHTMLElement vElement in vDocument.all)
if (vElement.tagName.ToUpper() == "FRAME ")
{
IHTMLFrameBase2 vFrameBase2 = vElement as IHTMLFrameBase2;
vFrameBase2.contentWindow.execScript(
"function alert(str){return;} ", "javaScript ");
}
}

原理就是声明同名自定义函数取代系统函数,其他函数替换也一样