Judge the summary of the browser kernel and version number method, and the kernel version number
Determine the browser kernel and version number through jquery
Copy codeThe Code is as follows:
<Script type = "text/javascript">
$ (Function (){
If ($. browser. msie & ($. browser. version = "7.0 ")){
$ ("# Yourannet" ).css ("margin-left", "10px ");
} // IE 7 Browser
Else if ($. browser. msie & ($. browser. version = "6.0 ")&&! $. Support. style ){
$ ("# Yourannet" ).css ("margin-left", "15px ");
} // IE 6 Browser
Else if ($. browser. msie & ($. browser. version = "8.0 ")){
$ ("# Yourannet" ).css ("margin-left", "20px ");
} // IE 8 browser
Else if ($. browser. msie & ($. browser. version = "9.0 ")){
$ ("# Yourannet" ).css ("margin-left", "25px ");
} // IE9 Browser
Else if (window. navigator. userAgent. toLowerCase (). indexOf ("360se")> = 1 ){
$ ("# Yourannet" ).css ("margin-left", "30px ");
} // Browser 360
})
JQuery uses regular expressions to match userAgent to determine the browser type and version.. How should we determine whether the current browser is IE6?
Copy codeThe 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! ");
}
Below isJquery Regular Expression: supports distinguishing ie, firefox, opera, chrome, and safari
Copy codeThe Code is as follows:
// Browser check ----- start
Var userAgent = navigator. userAgent, // userAgent
RMsie =/. * (msie) ([\ w.] +). */, // ie
RFirefox =/. * (firefox) \/([\ w.] +). */, // firefox
ROpera =/(opera). + version \/([\ w.] +)/, // opera
RChrome =/. * (chrome) \/([\ w.] +). */, // chrome
RSafari =/. * version \/([\ w.] +). * (safari). */; // safari
JMeteor. browser = {};
Var ua = userAgent. toLowerCase ();
Function uaMatch (ua ){
Var match = rMsie.exe c (ua );
If (match! = Null ){
Return {browser: match [1] exact future "", version: match [2] exact future "0 "};
}
Var match = rFirefox.exe c (ua );
If (match! = Null ){
Return {browser: match [1] exact future "", version: match [2] exact future "0 "};
}
Var match = rOpera.exe c (ua );
If (match! = Null ){
Return {browser: match [1] exact future "", version: match [2] exact future "0 "};
}
Var match = rChrome.exe c (ua );
If (match! = Null ){
Return {browser: match [1] exact future "", version: match [2] exact future "0 "};
}
Var match = rSafari.exe c (ua );
If (match! = Null ){
Return {browser: match [2] exact future "", version: match [1] exact future "0 "};
}
If (match! = Null ){
Return {browser: "", version: "0 "};
}
}
Var browserMatch = uaMatch (userAgent. toLowerCase ());
If (browserMatch. browser ){
JMeteor. browser [browserMatch. browser] = true;
JMeteor. browserName = browserMatch. browser;
JMeteor. browser. version = browserMatch. version;
JMeteor. browser. language = (navigator. language? Navigator. language
: Navigator. userLanguage completion succeeded "");
}
// Browser check ----- end
Usage:
Javascript code
JMeteor. browser. msie // determines whether it is ie. If true is returned, it indicates
JMeteor. browserName // browser name
JMeteor. browser. version // browser version
JMeteor. browser. language // language
</Script>
Determine browsers Based on browser version information
Copy codeThe Code is as follows:
Var _ uat = navigator. userAgent;
If (_ uat. indexOf ("MSIE 6.0")> 0) alert ("ie6 ");
Else if (_ uat. indexOf ("MSIE 7.0")> 0) alert ("ie7 ");
Else if (_ uat. indexOf ("MSIE 8.0")> 0) alert ("ie8 ");
Else if (_ uat. indexOf ("Firefox")> 0) alert ("firefox ");
CSS judgment Browser
Copy codeThe Code is as follows:
# Example {color: red;}/* firefox */
* Html # example {color: blue;}/* ie6 */
* + Html # example {color: green;}/* ie7 */
HTML browser judgment
Copy codeThe Code is as follows:
1. <! -- [If! IE]> <! --> All except IE can be recognized <! -- <! [Endif] -->
2. <! -- [If IE]> all IE identifiable <! [Endif] -->
3. <! -- [If IE 6]> only IE6 can recognize <! [Endif] -->
4. <! -- [If lt IE 6]> versions earlier than IE6 and IE6 are recognizable <! [Endif] -->
5. <! -- [If gte IE 6]> IE6 and IE6 and later versions can be recognized <! [Endif] -->
6. <! -- [If IE 7]> only IE7 is recognizable <! [Endif] -->
7. <! -- [If lt IE 7]> versions earlier than IE7 and IE7 are recognizable <! [Endif] -->
8. <! -- [If gte IE 7]> IE7 and IE7 versions can be identified <! [Endif] -->