C# WebBrowser自动点击弹出提示框

 时间:2026-04-26 18:50:16

1、方法一:通过设置Webbrowser的属性来实现

将WebBrowser控件ScriptErrorsSuppressed设置为True即可

C# WebBrowser自动点击弹出提示框

2、方法二:通过控制webbrowser加载后就点击掉,以达到效果

private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { 

      IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;

      vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); 

      vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");

}

3、方法三:在页面加载完成后自动关闭,与方法二大体相同

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){  

         IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument;  

          vDocument.parentWindow.execScript("function confirm(str){return true;} ", "javascript"); 

           vDocument.parentWindow.execScript("function alert(str){return true;} ", "javaScript");

}

  • VB6.0自定义图标的加载及注意事项
  • 批处理入门教程-findstr命令
  • 怎样使用VBA让控件适合窗体的缩放?
  • excel显示内存不足问题
  • 数据展示软件FineReport中如何在单元格显示图片
  • 热门搜索
    综合实践手抄报 四年级环保手抄报 伊索寓言手抄报 小学生安全手抄报图 保护眼睛的手抄报 小组手抄报 关于健康的手抄报图片 防地震手抄报内容 安全在我心手抄报 科技节手抄报资料