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

How does jquery determine whether it is an IE browser?

青灯夜游
Release: 2020-12-21 16:21:47
Original
2750 people have browsed it

In jquery, you can use the "jQuery.browser" method to determine the browser type. It can return relevant information about the browser currently used by the user and determine the syntax "if($.browser.msie) {/ /is ie browser}".

How does jquery determine whether it is an IE browser?

The operating environment of this tutorial: windows7 system, jquery1.8 version, this method is suitable for all brands of computers.

Recommended tutorial: jquery video tutorial

JQuery can use the jQuery.browser method to determine the browser type. This method can return relevant information about the browser currently used by the user. .

Parameters:

  • webkit Boolean type indicates whether it is a browser with webkit core.

  • safari Boolean type indicates whether it is the Apple Safari browser.

  • opera Boolean type indicates whether it is an opera browser.

  • msie Boolean type indicates whether it is Microsoft IE browser.

  • mozilla Boolean type indicates whether it is a Mozilla FireFox browser.

  • chrome Boolean type indicates whether it is the Google Chrome browser.

  • version String type The version number of the current browser, for example: "6.0", "7.0".

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

For more programming-related knowledge, please visit: Introduction to Programming! !

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:
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