Home > Web Front-end > JS Tutorial > body text

Example code of navigator.userAgent changes in IE11

零下一度
Release: 2017-06-30 10:15:36
Original
1567 people have browsed it

When we originally judged whether the browser was IE, we could always use MSIE in navigator.userAgent, but IE11 has changed and userAgent no longer contains the MSIE field.

In the actual project, something like The error reported in the console is when verifying the browser model. The specific method is as follows:

Function getBrowserInfo(){

var Sys = {};

var ua = navigator.userAgent.toLowersCase();

var re = /(msie I firefox | chrome | opera | version).*?([\d.]+)/;

var m = ua.match(re);

Sys.browser = m[1].replace(/version/,"'safari'");

Sys.ver = m [2];

    return;

  }

  According to this method, you can get the specific browser information in Sys. You can directly call this method for comparison. That's it;

But the production environment suddenly cannot log in. User feedback is that IE11 is used for the operation, so IE11 is used for testing directly. The specific error is as follows:

  【 SCRIPT5007: Unable to obtain undefined or The attribute "1" referenced by null ]

According to the error display position, m cannot be obtained after positioning after regular matching;

After resolution, the ie11 browser navigator.userAgent has changed, specifically becoming: . NET4.0C; .NET4.0E; Shuame; rv:11.0) like Gecko";

So replace the regular judgment: var re = /(msie I firefox | chrome | opera | version | rv:).* ?([\d.]+)/;

In this way, the problem is solved. The compatibility of ie11 has been greatly improved. There are still many improvements to be continued. . . . . . . . . . . . . . . . . . .

The above is the detailed content of Example code of navigator.userAgent changes in IE11. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!