Home Web Front-end JS Tutorial JQUERY1.6 usage method four: detect browser_jquery

JQUERY1.6 usage method four: detect browser_jquery

May 16, 2016 pm 05:59 PM
jquery Browser

userAgent = navigator.userAgent,//User Agent is called user agent in Chinese, or UA for short. It is a special string header that enables the server to identify the operating system and version, CPU type, browser and version, and browser rendering used by the customer. Engine, browser language, browser plug-in, etc.

The following are the navigator.userAgent of each browser

//Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN) AppleWebKit/533.21.1 (KHTML, like Gecko ) Version/5.0.5 Safari/533.21.1 --safari

//Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1 --chrome

//Opera/9.80 (Windows NT 5.1; U; Edition Next; zh-cn) Presto/2.8.158 Version/11.50 --opera

//Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; .NET4.0C; .NET4.0E; InfoPath.2) ---ie

//Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.24) Gecko/20111103 Firefox/3.6.24 --firefox



//Regular for matching response browser representation

rwebkit = /(webkit)[ /]([w.] )/,//webkit
ropera = /(opera)( ?:.*version)?[ /]([w.] )/,//opera
rmsie = /(msie) ([w.] )/,//ie
rmozilla = /(mozilla) (?:.*? rv:([w.] ))?/,//mozilla



Through userAgent, we can see that chrome can be matched in the following way, but because Like safari, both have "safari". We can put it in front of rwebkit. to match

rchrome=/(Chrome)[ /]([w.] )/

Firefox can also do the same, put it in front of rmozilla for judgment

rfirefox=/(Firefox)[ /]([w.] )/



uaMatch : function(ua) {//Mainly the type and version of the browser obtained
ua = ua.toLowerCase();//The parameter is navigator.userAgent. Convert to lowercase. Of course, you can also declare case-insensitivity in the regular match (such as /(webkit)[ /]([w.] )/i)

var match = rwebkit.exec(ua) | |
ropera.exec( ua ) ||
rmsie.exec( ua ) ||
ua.indexOf("compatible") [] ;//Since exec is used for matching, the returned result is an overall match and a submatch of the response, such as /(Chrome)[ /]([w.] )/, match will return Chrome/13.0.782.220, match[1 ] get chrome, match[2] get 13.0.782.220;

return { browser: match[1] || "", version: match[2] || "0" };
}

//uaMatch is a method in jQuery. Here, start calling and saving the browser model browser and version

browserMatch = jQuery.uaMatch( userAgent ); // Call uaMatch, and Return object return { browser: match[1] || "", version: match[2] || "0" };
if ( browserMatch.browser ) {
jQuery.browser[ browserMatch.browser ] = true;//chromesafarioperamsiemozilla, for example, when we want to perform a specific operation under the opera browser, we can use $.browser.opera to determine whether it is the opera browser (true, false)

jQuery.browser.version = browserMatch.version;//Browser version
}


if ( jQuery.browser.webkit ) {
jQuery.browser.safari = true;//Because safari uses AppleWebKit The engine, since Safari and Chrome both have it, are being processed separately
}

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1271
29
C# Tutorial
1251
24
How to register an account on Ouyi Exchange Ouyi Exchange Registration Tutorial How to register an account on Ouyi Exchange Ouyi Exchange Registration Tutorial Apr 24, 2025 pm 02:06 PM

The steps to register an Ouyi account are as follows: 1. Prepare a valid email or mobile phone number and stabilize the network. 2. Visit Ouyi’s official website. 3. Enter the registration page. 4. Select email or mobile phone number to register and fill in the information. 5. Obtain and fill in the verification code. 6. Agree to the user agreement. 7. Complete registration and log in, carry out KYC and set up security measures.

Download the official website of Ouyi Exchange app for Apple mobile phone Download the official website of Ouyi Exchange app for Apple mobile phone Apr 28, 2025 pm 06:57 PM

The Ouyi Exchange app supports downloading of Apple mobile phones, visit the official website, click the "Apple Mobile" option, obtain and install it in the App Store, register or log in to conduct cryptocurrency trading.

Binance download link Binance download path Binance download link Binance download path Apr 24, 2025 pm 02:12 PM

To safely download the Binance APP, you need to go through the official channels: 1. Visit the Binance official website, 2. Find and click the APP download portal, 3. Choose to scan the QR code, app store, or directly download the APK file to download to ensure that the link and developer information are authentic, and enable two-factor verification to protect the security of the account.

Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Sesame Open Door Official Website Entrance Sesame Open Door Official Latest Entrance 2025 Apr 28, 2025 pm 07:51 PM

Sesame Open Door is a platform that focuses on cryptocurrency trading. Users can obtain portals through official websites or social media to ensure that the authenticity of SSL certificates and website content is verified during access.

Ouyi official website entrance Ouyi official latest entrance 2025 Ouyi official website entrance Ouyi official latest entrance 2025 Apr 28, 2025 pm 07:48 PM

Choose a reliable trading platform such as OKEx to ensure access to the official entrance.

How to register an account on Sesame Open Exchange? Tutorial on Registration of Sesame Open Exchange How to register an account on Sesame Open Exchange? Tutorial on Registration of Sesame Open Exchange Apr 24, 2025 pm 02:00 PM

Registering a Sesame Door Account requires 7 steps: 1. Prepare a valid email or mobile phone number and a stable network; 2. Visit the official website; 3. Enter the registration page; 4. Select and fill in the registration method; 5. Obtain and fill in the verification code; 6. Agree to the user agreement; 7. Complete registration and log in, it is recommended to carry out KYC and set security measures.

What is on-chain transaction? What are the global transactions? What is on-chain transaction? What are the global transactions? Apr 22, 2025 am 10:06 AM

EU MiCA compliance certification, covering 50 fiat currency channels, cold storage ratio 95%, and zero security incident records. The US SEC licensed platform has convenient direct purchase of fiat currency, a ratio of 98% cold storage, institutional-level liquidity, supports large-scale OTC and custom orders, and multi-level clearing protection.

Binance official website entrance Binance official latest entrance 2025 Binance official website entrance Binance official latest entrance 2025 Apr 28, 2025 pm 07:54 PM

Visit Binance official website and check HTTPS and green lock logos to avoid phishing websites, and official applications can also be accessed safely.

See all articles