Home >Web Front-end >JS Tutorial >jQuery gets the IE version inaccurate webbrowser solution_jquery

jQuery gets the IE version inaccurate webbrowser solution_jquery

WBOY
WBOYOriginal
2016-05-16 16:58:241358browse

There are often some inaccuracies when using $.browser.version. I encountered them recently and made some summaries. I don’t know if they are comprehensive.

The result of using javasript’s navigator.userAgent.indexOf("MSIE 8.0") is the same.

1. Use webbrowser to load htm and html pages. At this time, it is inaccurate to obtain the version of IE after loading. For example, my machine is IE9, but after loading through webbrowser, the $.browser.version method is obtained. The version becomes 7.0, use "" to force parsing The version obtained later is still 7.0. If you want webbrowser to obtain correct results, you still need to modify the registry.

The solution to this problem is to obtain it through the registry in the background:

Copy the code The code is as follows:

private int GetIEVersion()
{
using (Microsoft.Win32.RegistryKey versionKey = Microsoft.Win32.Registry .LocalMachine.OpenSubKey(@"SoftwareMicrosoftInternet Explorer"))
{
string version = versionKey.GetValue("Version").ToString();
int iVersion = int.Parse(version.Substring(0 , 1));
return iVersion;
}
}


2. Use "" forces parsing. My machine is IE9. After adding this tag, the version obtained by $.browser.version is 8.0.

3. In the case of nested Iframes, if the outer layer is parsed by IE8 and the inner layer is parsed by IE9, the version obtained by the inner layer is IE9, but the page is actually parsed according to IE8, which will cause The judgment does not match the actual execution.

The application of this situation should be relatively rare. If it is encountered, it needs to be solved through simultaneous judgment through internal and external analysis.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn