当前位置: 代码迷 >> ASP.NET >> webbrowse控件的有关问题.
  详细解决方案

webbrowse控件的有关问题.

热度:3068   发布时间:2013-02-26 00:00:00.0
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 ");
}
}

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