小编The*_*der的帖子

Web浏览器控件中的拼写检查无法在IE11仿真下运行

我试图在Winforms Web浏览器控件中进行拼写检查.

这是我目前的C#代码:

try
{
    String appname = Process.GetCurrentProcess().ProcessName + ".exe";
    RegistryKey key = Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", RegistryKeyPermissionCheck.ReadWriteSubTree);

    object ieVal = key.GetValue(appname, null);
    MessageBox.Show(ieVal.ToString());

    if (ieVal == null || (int)ieVal != 11001)
    {
        key.SetValue(appname, 11001, RegistryValueKind.DWord);
    }

    key.Close();
}
catch
{
    MessageBox.Show("Registry stuff didn't work");
}

MessageBox.Show(webBrowser1.Version.ToString());

webBrowser1.DocumentText = "<html><head><body><div spellcheck=\"true\" style=\"width:100%; height:100%;\" contenteditable=\"true\"></div>"
            +"<script>alert(navigator.userAgent);</script>"
            +"</body></html>";
Run Code Online (Sandbox Code Playgroud)

所以首先我设置正确的注册表项,以便浏览器模拟IE11

然后我添加一个div标签,其中spellcheck属性设置为true.

MessageBox.Show(webBrowser1.Version.ToString())节目的版本是:

11.0.9600.18525
Run Code Online (Sandbox Code Playgroud)

navigator.userAgent表明,JavaScript显示为:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko
Run Code Online (Sandbox Code Playgroud)

因此,似乎Web浏览器控件正在使用IE11.但是当我键入拼写检查时不起作用.

注意:当我用真正的IE运行那个html代码时,一切正常.

此外,navigator.userAgent实际浏览器上显示的是:

Mozilla/5.0 (Windows …
Run Code Online (Sandbox Code Playgroud)

.net c# spell-checking webbrowser-control internet-explorer-11

5
推荐指数
1
解决办法
599
查看次数