2

特定の Web ページからデータをロードするために使用される非表示の Web ブラウザー コントロールを持つプログラムを開発しています。ただし、特定の種類のポップアップをブロックするのに問題があります。

これは、ポップアップをブロックするために現在使用しているコードです

private void webBrowser1_NewWindow( object sender, 
                                    System.ComponentModel.CancelEventArgs e)
{
  e.Cancel = true;
}

http://www.popuptest.com/でテストしましたが、カム アンド ゴー テストとモードレス ウィンドウ テストをブロックできません。http://i75.servimg.com/u/f75/13/13/40/49/b11.png

これらのポップアップをブロックする方法はありますか?

これは、ポップアップを表示する JavaScript です。

function modelesswin(url,mwidth,mheight){
if (document.all&&window.print) //if ie5
    eval('window.showModelessDialog(url,"","help:0;resizable:1;dialogWidth:'+mwidth+'px;dialogHeight:'+mheight+'px")')
else
eval('window.open(url,"","width='+mwidth+'px,height='+mheight+'px,resizable=1,scrollbars=1")')
}


modelesswin("http://www.popuptest.com/popup1.html",600,600)
4

1 に答える 1

4

WebBrowser Feature Control、特にFEATURE_BLOCK_INPUT_PROMPTSFEATURE_WEBOC_POPUPMANAGEMENTを実装してみてください。

[編集済み]このコードはあなたのテスト サイトで動作します。試してみてください (IE10 でテスト済み)。WebBrowser が作成される前 (InitializeComponent以下の前)に機能を設定ScriptErrorsSuppressed = trueし、ブロックされたポップアップによって引き起こされるスクリプト エラーを抑制するようにしてください。

using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;

namespace WinformsWB
{
    public partial class Form1 : Form
    {
         public Form1()
        {
            SetBrowserFeatureControl();
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.webBrowser1.ScriptErrorsSuppressed = true;
            this.webBrowser1.Navigate("http://www.popuptest.com/");
        }

        private void SetBrowserFeatureControlKey(string feature, string appName, uint value)
        {
            using (var key = Registry.CurrentUser.CreateSubKey(
                String.Concat(@"Software\Microsoft\Internet Explorer\Main\FeatureControl\", feature),
                RegistryKeyPermissionCheck.ReadWriteSubTree))
            {
                key.SetValue(appName, (UInt32)value, RegistryValueKind.DWord);
            }
        }

        private void SetBrowserFeatureControl()
        {
            // http://msdn.microsoft.com/en-us/library/ee330720(v=vs.85).aspx

            // FeatureControl settings are per-process
            var fileName = System.IO.Path.GetFileName(Process.GetCurrentProcess().MainModule.FileName);

            // make the control is not running inside Visual Studio Designer
            if (String.Compare(fileName, "devenv.exe", true) == 0 || String.Compare(fileName, "XDesProc.exe", true) == 0)
                return;

            // TODO: FEATURE_BROWSER_MODE - what is it?
            SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, 9000); // Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
            SetBrowserFeatureControlKey("FEATURE_DISABLE_NAVIGATION_SOUNDS", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_WEBOC_POPUPMANAGEMENT", fileName, 1);
            SetBrowserFeatureControlKey("FEATURE_BLOCK_INPUT_PROMPTS", fileName, 1);
        }
    }
}
于 2013-08-24T02:11:49.163 に答える