仿真 > IE7 时 WPF WebBrowser 控件出现问题
Issue With WPF WebBrowser Control When Emulation > IE7
我有一个 C#/WPF 应用程序,它使用 WebBrowser 控件,将网站作为其主要界面(用于信息亭)。该网站可以通过 javascript 调用 C# 方法进行一些本机处理。一切正常,直到我将 'FEATURE_BROWSER_EMULATION' 设置为高于 IE7(使用下面的代码)。当我对本机方法进行 javascript 调用时,除非我 运行 来自“http://localhost”的网站工作正常,否则不会被调用。
我假设这是一个安全问题。我搞砸了 IE 中的所有安全设置(包括将站点设置为 'Trusted Site'),但我似乎无法正常工作。
编码我正在使用设置仿真:
private void SetBrowserCompatibilityMode()
{
// 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 );
if ( String.Compare( fileName, "devenv.exe", true ) == 0 ) // make sure we're not running inside Visual Studio
return;
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
UInt32 mode = 11000; // 11000 = IE11, 10000 = IE10, 9000 = IE9, 8000 = IE8, 7000 = IE7;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable zone elevation prevention
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// enable <scripts> in local machine zone
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMODE",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable Legacy Input Model
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
}
尝试以下方法之一:
1- 运行 您作为管理员的程序。
2- 检查您的 JavaScript 是否与您正在模拟的版本兼容,如 IE7 上的某些 JavaScript 代码 运行 但不是更高版本。
更新:
这是我设置仿真的方式,请注意,如果您不以管理员身份 运行,此代码将无法工作:
private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
{
RegistryKey Regkey = null;
try
{
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
//If the path is not correct or
//If user't have priviledges to access registry
if (Regkey == null)
{
_logger.Error("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
//Check if key is already present
if (FindAppkey == ieval.ToString())
{
_logger.Debug("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
Regkey.Close();
return;
}
//If key is not present or different from desired, add/modify the key , key value
Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);
//check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == ieval.ToString())
{
_logger.Info("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
}
else
{
_logger.Error("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval);
}
}
catch (Exception ex)
{
_logger.Error("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);
}
finally
{
//Close the Registry
if (Regkey != null) Regkey.Close();
}
}
并使用函数:
var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";
int ie_emulation = 9000;
禁用 FEATURE_LOCALMACHINE_LOCKDOWN
、FEATURE_BLOCK_LMZ_SCRIPT
、FEATURE_BLOCK_LMZ_OBJECT
功能。您可以改编 . Alternatively, I believe you can use "Mark of Web" 中的工作 C# 代码,再次制作您的脚本 运行。
我有一个 C#/WPF 应用程序,它使用 WebBrowser 控件,将网站作为其主要界面(用于信息亭)。该网站可以通过 javascript 调用 C# 方法进行一些本机处理。一切正常,直到我将 'FEATURE_BROWSER_EMULATION' 设置为高于 IE7(使用下面的代码)。当我对本机方法进行 javascript 调用时,除非我 运行 来自“http://localhost”的网站工作正常,否则不会被调用。
我假设这是一个安全问题。我搞砸了 IE 中的所有安全设置(包括将站点设置为 'Trusted Site'),但我似乎无法正常工作。
编码我正在使用设置仿真:
private void SetBrowserCompatibilityMode()
{
// 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 );
if ( String.Compare( fileName, "devenv.exe", true ) == 0 ) // make sure we're not running inside Visual Studio
return;
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode.
UInt32 mode = 11000; // 11000 = IE11, 10000 = IE10, 9000 = IE9, 8000 = IE8, 7000 = IE7;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_ZONE_ELEVATION",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable zone elevation prevention
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BLOCK_LMZ_SCRIPT",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// enable <scripts> in local machine zone
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
using ( var key = Registry.CurrentUser.CreateSubKey( @"Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_NINPUT_LEGACYMODE",
RegistryKeyPermissionCheck.ReadWriteSubTree ) )
{
// disable Legacy Input Model
UInt32 mode = 0;
key.SetValue( fileName, mode, RegistryValueKind.DWord );
}
}
尝试以下方法之一: 1- 运行 您作为管理员的程序。 2- 检查您的 JavaScript 是否与您正在模拟的版本兼容,如 IE7 上的某些 JavaScript 代码 运行 但不是更高版本。
更新: 这是我设置仿真的方式,请注意,如果您不以管理员身份 运行,此代码将无法工作:
private static void SetIEVersioneKeyforWebBrowserControl(string appName, int ieval)
{
RegistryKey Regkey = null;
try
{
Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true);
//If the path is not correct or
//If user't have priviledges to access registry
if (Regkey == null)
{
_logger.Error("Application FEATURE_BROWSER_EMULATION Failed - Registry key Not found");
return;
}
string FindAppkey = Convert.ToString(Regkey.GetValue(appName));
//Check if key is already present
if (FindAppkey == ieval.ToString())
{
_logger.Debug("Application FEATURE_BROWSER_EMULATION already set to " + ieval);
Regkey.Close();
return;
}
//If key is not present or different from desired, add/modify the key , key value
Regkey.SetValue(appName, unchecked((int)ieval), RegistryValueKind.DWord);
//check for the key after adding
FindAppkey = Convert.ToString(Regkey.GetValue(appName));
if (FindAppkey == ieval.ToString())
{
_logger.Info("Application FEATURE_BROWSER_EMULATION changed to " + ieval + "; changes will be visible at application restart");
}
else
{
_logger.Error("Application FEATURE_BROWSER_EMULATION setting failed; current value is " + ieval);
}
}
catch (Exception ex)
{
_logger.Error("Application FEATURE_BROWSER_EMULATION setting failed; " + ex.Message);
}
finally
{
//Close the Registry
if (Regkey != null) Regkey.Close();
}
}
并使用函数:
var targetApplication = Process.GetCurrentProcess().ProcessName + ".exe";
int ie_emulation = 9000;
禁用 FEATURE_LOCALMACHINE_LOCKDOWN
、FEATURE_BLOCK_LMZ_SCRIPT
、FEATURE_BLOCK_LMZ_OBJECT
功能。您可以改编