Home > Web Front-end > JS Tutorial > How does jquery determine whether it is an IE browser?

How does jquery determine whether it is an IE browser?

王林
Release: 2020-11-30 14:55:00
Original
3092 people have browsed it

Jquery method to determine whether it is an IE browser: You can use the jquery browser method to determine, such as [$.browser.msie]. If we still need to distinguish the version, we need to use [jQuery.browser.version 】method.

How does jquery determine whether it is an IE browser?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version. This method is suitable for all brands of computers.

(Learning video sharing: javascript video tutorial)

Jquery method to determine whether it is an IE browser:

JQuery You can use the jQuery.browser method to determine the browser type. The return value can be: safari, opera, msie, mozilla. If the return value is msie, it means the browser is ie.

Of course sometimes we also need to distinguish versions, which requires the use of jQuery.browser.version.

Example:

function JudgeBroswer() {
        if($.browser.msie) {
            alert("this is msie!"); //IE        }
        else if($.browser.safari)
        {
            alert("this is safari!"); //Safari         }
        else if($.browser.mozilla)
        {
            alert("this is mozilla!");  //Firefox        }
        else if($.browser.opera) {
            alert("this is opera");     //Opera        }
    }
Copy after login

jquery source code:

var userAgent = navigator.userAgent.toLowerCase();   
// Figure out what browser is being used
   jQuery.browser = {
    version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
    safari: /webkit/.test(userAgent),
    opera: /opera/.test(userAgent),
    msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
    mozilla:/mozilla/.test(userAgent)&&!/(compatible|webkit)/.test(userAgent)
    };
Copy after login

Related recommendations: js tutorial

The above is the detailed content of How does jquery determine whether it is an IE browser?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template