Home>Article>Web Front-end> Example code of navigator.userAgent changes in IE11

Example code of navigator.userAgent changes in IE11

零下一度
零下一度 Original
2017-06-30 10:15:36 1406browse

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!

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