Determine the browser version type based on jQuery1.9 and jquery

Source: Internet
Author: User

Determine the browser version type based on jQuery1.9 and jquery

For versions earlier than jquery.1.9, you can use $. browser can easily determine the type and version of the browser, but in Versions 1.9 and later, $. browser has been deleted. Next we will introduce how to implement this function and hope to help you.

I. Custom Code:

$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase()); $.browser.webkit = /webkit/.test(navigator.userAgent.toLowerCase()); $.browser.opera = /opera/.test(navigator.userAgent.toLowerCase()); $.browser.msie = /msie/.test(navigator.userAgent.toLowerCase()); 

In the above Code, the return value of the expression after the equal sign is Boolean to indicate whether the browser is supported. In this way, the custom $. browser effect is realized.

Ii. Judge IE6 Browser:

Use the following code before jquery1.9:

if ($.browser.msie && 7 > $.browser.version) {} 

Jquery1.9 and later use the following code:

if ('undefined' == typeof(document.body.style.maxHeight)) {} 

3. Judge the IE6-IE8 Browser:

if (!$.support.leadingWhitespace) {} 

To sum up, we have basically met our requirements. We will not discuss them here.

Extended knowledge points:

JQuery. browser definition and usage:

The browser kernel ID, which is determined by navigator. userAgent.

Available values: safari, opera, msie, and mozilla.

The browser object detection technology works with this property to provide reliable browser detection support.

It has been deleted in jQuery 1.9.

If the webpage runs in opera browser, jQuery. browser. opera returns true; otherwise, false.
Other property values are similar.

Instance code:

<! DOCTYPE html> 

Usage of the typeof OPERATOR:

Before an operand, the typeof operator can detect the Data Type of the operand and return a string to describe the type of the operand.
The operands can be variables or values.

Possible values returned by the typeof OPERATOR:

1. If the variable is not assigned a value or the value of the variable is undefined, undefined is returned.

Instance:

var aconsole.log(typeof(a))

Variable a is not assigned a value. In this case, the variable is implicitly assigned an undefined value by default. Output result: undefined.

var a=undefined;console.log(typeof(a))

Variable a is assigned undefined. Output result: undefined.

2. If the variable or value type is boolean, return boolean.

Instance code:

console.log(typeof (true))

Output result: boolean.

var a=2,b=1,c=3,d;d=a+b;console.log(typeof(c==d))

Output result: boolean.

3. If the variable or value is of the numerical type, return number.

console.log(typeof(1))

Output result: number.

4. If the variable or value is a string, the return value is string.

console.log(typeof("mayi"))

Output result: string.

console.log(typeof("a"))

ECMAScript has no character type. Therefore, this code also outputs a string.

5. If the variable is of the reference type or null, the object is returned.

Note: null can be considered as a placeholder of an object, so the returned value is also an object.

Instance code:

var a=new Date;console.log(typeof(a))

Create a time object instance a, which is a reference type. Output result: objct.

console.log(typeof(null))

Output result: object.

6. If the variable is a function, the function is returned.

Console. log (typeof (function () {alert ("Hello everyone ")}))

Output result: function.

Var a = function () {alert ("Hello everyone")} console. log (typeof ())

Output result: function.

Articles you may be interested in:
  • Use jQuery to detect the script code of browsers and versions
  • Use jQuery extension to identify the type and version of the browser kernel and Shell
  • Code for jquery to determine the browser type
  • Native javascript and jquery determine the browser version and other information
  • How to check the browser type and version in jquery1.9
  • Use jQuery to determine the code of the IE browser version
  • Summary of js/jquery methods for determining browser types

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.