Under jQuery, the browser is determined through $.browser.
Use jQuery to determine the type of browser, mainly using the $.browser tool class
Usage method:
$.browser.['browser keyword' ]
The code is as follows:
$(function() { if($.browser.msie) { alert("this is msie"); } else if($.browser.safari) { alert("this is safari!"); } else if($.browser.mozilla) { alert("this is mozilla!"); } else if($.browser.opera) { alert("this is opera"); } else { alert("i don't konw!"); }
Let’s take a look at the source code of jQuery:
The code is as follows:
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 ) };
jQuery What is used is to match the userAgent with regular rules to determine the type and version of the browser.
If we want to determine whether the current browser is IE6, how should we determine it?
$.browser.msie&&($.browser.version == "6.0")&&!$.support.style
Similarly jQuery determines whether the browser is IE7
$.browser.msie&&($.browser .version == "7.0")
If you do not consider backward compatibility and do not want to import jQuery in order to determine each browser type
The easiest way to determine IE is
code As follows:
if( document .all){ alert("IE6") }
$.browser uses regular expression to match userAgent to determine the browser version and type. jquery.browser and jquery have been declared in the jquery1.3.2 version of the document. It is recommended that browser.version be deprecated and jquery.support can be used instead
But judging from the current situation, jquery.support is not easy to use and is very difficult to use. We still use $.browser honestly. Determine the browser type
If it is to determine the version of IE, I still recommend using IE’s conditional expression to write JS
The code is as follows:
<!--[if IE]> <script type="text/ javascript "> alert("ie") </script> <![endif]--> <!--[if IE 6]> <script type="text/javascript"> alert("ie6") </script> <![endif]--> <!--[if IE 7]> <script type="text/javascript"> alert("ie7") </script> <![endif]-->
This is easier than our manual It is more accurate to judge the IE version through $.browser, and there is no need to remember how to use jquery's browser
The above is the detailed content of Under jQuery, the browser is determined through $.browser.. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To remove FirefoxSnap in Ubuntu Linux, you can follow these steps: Open a terminal and log in to your Ubuntu system as administrator. Run the following command to uninstall FirefoxSnap: sudosnapremovefirefox You will be prompted for your administrator password. Enter your password and press Enter to confirm. Wait for command execution to complete. Once completed, FirefoxSnap will be completely removed. Note that this will remove versions of Firefox installed via the Snap package manager. If you installed another version of Firefox through other means (such as the APT package manager), you will not be affected. Go through the above steps

Mozilla Firefox can be uninstalled; Firefox is a third-party browser and can be uninstalled if it is not needed. Uninstallation method: 1. In the Start menu, click "Windwos System" - "Control Panel"; 2. In the "Control Panel" interface, click "Programs and Features"; 3. In the new interface, find and double-click Firefox Browser icon; 4. In the uninstall pop-up window, click "Next"; 5. Click "Uninstall".

According to recent news, while Mozilla released the stable version of Firefox 112, it also announced that the next major version, Firefox 113, has entered the Beta channel and supports AV1 animations, enhanced password generator and picture-in-picture features. The main new functions/features of Firefox 113 are as follows: Support for AV1 format animated images (AVIS); Enhance the security of the password generator by introducing special characters; Enhance the picture-in-picture function, support rewind, display video time, and enable full screen more easily Mode provides official DEB installation files for Debian and Ubuntu distributions. Updated bookmark import feature, icons for imported bookmarks are supported by default. Hardware accelerated AV1 video decoding is enabled by default on supported hardware using w

For crawlers to crawl websites that require login, verification code or scan code login is a very troublesome problem. Scrapy is a very easy-to-use crawler framework in Python, but when processing verification codes or scanning QR codes to log in, some special measures need to be taken. As a common browser, Mozilla Firefox provides a solution that can help us solve this problem. The core module of Scrapy is twisted, which only supports asynchronous requests, but some websites require the use of cookies and

Apple has released updates for iPhone, iPad, Mac and Apple Watch. Although the updates for each device are small, they address WebKit vulnerabilities. The company also assured that it has fixed a bug that caused MacBook laptops to unexpectedly drain their batteries. Apple iOS and iPadOS 15.3.1 are minor updates. It doesn't actually contain any major features. However, it is useful for people using braille displays. Additionally, the update resolves an arbitrary code execution vulnerability. The update notes for iOS 15.3.1 mention: iOS 15.3.1 provides important security updates for your iPhone and fixes

Canonical recently announced that in the upcoming Ubuntu 23.10, Firefox Snap has been configured to run in Wayland mode by default. Note: Ubuntu currently has the Wayland session by default, and Firefox can also work normally. However, currently FirefoxSnap actually runs in XWayland compatibility mode, rather than the strict native Wayland mode. Canonical announced that it will run the Firefox browser in Wayland mode by default, so that problems such as interface blur and scaling distortion will not occur on HiDPI displays, and it will support touch gestures such as dragging and pinching. As mentioned above, Ubunt

According to news on January 26, after iPhone users in Europe upgrade to the iOS17.4Beta1 update, they will see a new window after opening the Safari browser, which supports changing the default browser. Users in Europe can set up non-Safari browsers including Firefox, Opera, Chrome, Brave and Microsoft Edge according to their own preferences. Browser apps can now also use browser engines other than WebKit, including browser apps and in-app browsing experiences. Apple previously required that all browsers on iOS, including common browsers such as Chrome and Firefox, must use the WebKit engine.

Today’s latest news, Mozilla officially released the Firefox 115 stable version update today. The most noteworthy thing about this update is that this is the last version that supports Win7/Win8, macOS10.12, 10.13 and 10.14. Download address: https://ftp.mozilla.org/pub/firefox/releases/115.0/Mozilla stated in the official update log: Microsoft will end support for Win7 and Win8 systems in January 2023, and Firefox 115 released today The version is the last version update received by users of said system. Win7 and Win8 users
