In previous versions of jquery.1.9, it was easy to use $.browser to determine the type and version of the browser, but in the 1.9 and later versions, $.browser has been removed, and here's how to implement this function in the hope of bringing help to friends who need it.
A. Custom code:
$.browser.mozilla =/firefox/.test (Navigator.userAgent.toLowerCase ());
$.browser.webkit =/webkit/.test (Navigator.userAgent.toLowerCase ());
$.browser.opera =/opera/.test (Navigator.userAgent.toLowerCase ());
In the preceding code, the expression return value after the equal sign is a Boolean type that indicates whether this browser is supported. This enables a custom $.browser effect.
Two. Judge IE6 Browser:
Use the following code before jquery1.9:
jquery1.9 and then use the following code:
Three. Judge Ie6-ie8 Browser:
To sum up, the basic realization of our requirements, here is not more introduced.
Expand Knowledge Points:
Definition and usage of Jquery.browser:
Browser kernel identification, based on navigator.useragent judgment.
Available values: Safari, Opera, MSIE and Mozilla.
The use of browser object detection technology in conjunction with this property provides reliable browser detection support.
has been removed in jquery 1.9.
If the Web page is running in Opera browser, JQuery.browser.opera returns TRUE, otherwise it returns false.
Other property values, and so on.
Instance code:
Use of the TypeOf operator:
Before the operand is placed, the typeof operator can detect the data type of this operand and return a string that describes the type of operand.
Operands can be variables or values, and so on.
The value that the TypeOf operator may return:
A. Returns undefined if the variable is not assigned or the variable value is assigned to undefined.
Instance instance:
var a
Console.log (typeof (a))
Variable A is not assigned a value, this time the variable is implicitly assigned by default undefined. Output result: undefined.
var a=undefined;
Console.log (typeof (a))
Variable A is assigned undefined. Output result: undefined.
Two. Returns a Boolean if the variable or value is a Boolean type.
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.
Three. If the variable or value is a numeric type, return number.
Output result: number.
Four. If the variable or value is a string, return string.
Console.log (typeof ("Mayi"))
Output result: string.
Console.log (typeof ("a"))
There are no character types in the ECMAScript. So this code will also output string.
Five. If the variable is a reference type or null, the object is returned.
Note: null can be considered a placeholder for an object, so the return value is also 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.
Six. If the variable is a function, return function
Console.log (typeof (function () {alert ("Everyone Good")})
Output result: function.
var a=function () {alert ("Everyone Good")}
Console.log (typeof (a))
Output result: function.