如何在WPF WebBrowser中修复document.execCommand(“ Bold”)

时间:2019-11-30 17:32:26

标签: c# wpf execcommand

我的HTML编辑器中有错误。

document.execCommand("Bold", false, null);
or
document.execCommand("italic", false, null);
or
document.execCommand("underline", false, null);

此代码将文本切换为粗体(斜体,下划线),但不要取消切换。 我发现了为什么会这样,但我不知道如何解决。 在我的项目中,我必须通过注册表指定IE版本。因此,当我不使用此代码时,一切正常(execCommand切换和取消切换文本格式):

private static void EnsureBrowserEmulationEnabled(bool uninstall = false)
        {
            var exename = Process.GetCurrentProcess().ProcessName + ".exe";
            try
            {
                RegistryKey rk;
                if (Environment.Is64BitOperatingSystem)
                    rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
                else
                    rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
                using (rk)
                {
                    if (!uninstall)
                    {
                        dynamic value = rk.GetValue(exename);

                        if (value == null || !value.ToString().Equals("11000"))
                            rk.SetValue(exename, (uint)11000, RegistryValueKind.DWord);
                    }
                    else
                        rk.DeleteValue(exename);
                }
            }
            catch
            {
            }
        }

我将在此处留下github链接。要禁用“ EnsureBrowserEmulationEnabled”功能,只需执行此操作

EnsureBrowserEmulationEnabled(true);

0 个答案:

没有答案