Especially in today's various browsers are flying (it is said that only IE is the kernel of the browser there are 200 kinds of).
Little brother today wrote a jquery based plug-in extension that identifies the type and version of the browser's kernel and shell. can identify the various browsers of the kernel, and has supported a variety of domestic mainstream browsers.
Crap not much to say, on my JavaScript code: (FileName: jquery.browsertype-1.0.js)
Copy Code code as follows:
/**
* jquery Plug-in Development method Two: The first step: plug-in definition
*/
Jquery.myplugin = {
Get the type and version of the browser's kernel and shell
Client:function () {
Browser kernel type (only five kinds)
var engine = {ie:0, webkit:0, gecko:0, opera:0, khtml:0};
Browser shell type (domestic common browsers are: 360 browsers, proud tour, Tencent Qq\tt Browser, window of the world, Comet browser, Green browser, traditional ie, Google Chrome, Netscape-Netscape, Firefox, Opera, Apple Safari, etc.)
var shell = {se360:0, se:0, maxthon:0, qq:0, tt:0, theworld:0, cometbrowser:0, greenbrowser:0, ie:0, chrome:0, netscape:0 , firefox:0, opera:0, safari:0, konq:0};
Obtaining information from the client browser
var ua = Navigator.userAgent.toLowerCase ();
for (var type in engine) {
if (typeof type = = ' string ') {
var regexp = ' gecko ' = = type? /RV: ([\w.] +)/: RegExp (Type + ' [\\/] ([\\w.] +)');
if (Regexp.test (UA)) {
Engine.version = Window.opera? Window.opera.version (): regexp.$1;//Browser kernel version
Engine[type] = parsefloat (engine.version);
Engine.type = type;//Browser kernel type
Break
}
}
}
for (var type in shell) {
if (typeof type = = ' string ') {
var regexp = null;
Switch (type) {
Case "se360": RegExp =/360SE (?: [\/] ([\w.] +))?/; Break
Case "se": regexp =/se ([\w.] +)/; Break
Case "QQ": RegExp =/qqbrowser\/([\w.] +)/; Break
Case "tt": regexp =/tencenttraveler ([\w.] +)/; Break
Case "Safari": regexp =/version\/([\w.] +)/; Break
Case "Konq": regexp =/konqueror\/([\w.] +)/; Break
Case "Netscape": regexp =/navigator\/([\w.] +)/; Break
Default:regexp = regexp (type + ' (?: [\\/] ([\\w.] +))?');
}
if (Regexp.test (UA)) {
Shell.version = Window.opera? Window.opera.version (): Regexp.$1? Regexp.$1: ' unknown ';//Browser Shell version
Shell[type] = parsefloat (shell.version);
Shell.type = type;//Browser Shell type
Break
}
}
}
Returns the type and version of the browser's kernel and shell: engine is the kernel, shell is shell
return {engine:engine, shell:shell};
}
};
/**
* jquery Plug-in Development method Two: The second step: the implementation of Plug-ins
* Jquery.mybrowser plugin: Get the type and version of the browser's kernel and shell
* Use examples:
* (1) Browser kernel: alert ("Your browser information is as follows: \ n kernel type:" +jquery.mybrowser.engine.type+ ", kernel version:" +jquery.mybrowser.engine.version);
* (2) Browser shell: alert ("Your browser information is as follows: \ n Shell type:" +jquery.mybrowser.shell.type+ ", Shell version:" +jquery.mybrowser.shell.version);
*/
Jquery.mybrowser = JQuery.myPlugin.Client ();
Use example: (test.html)
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<title> access to browser information </title>
<script type= "Text/javascript" src= "Https://www.google.com/jsapi" ></script>
<script type= "Text/javascript" >
Google.load ("jquery", "1.4.2");
Google.load ("jQueryUI", "1.7.2");
</script>
<script type= "Text/javascript" src= "Jquery.browsertype-1.0.js" ></script>
<script type= "Text/javascript" >
Alert ("Your browser information is as follows: \ n kernel type:" +jquery.mybrowser.engine.type+ ", kernel version:" +jquery.mybrowser.engine.version);
Alert ("Your browser information is as follows: \ n Shell type:" +jquery.mybrowser.shell.type+ ", Shell version:" +jquery.mybrowser.shell.version);
Document.writeln ("Your browser kernel type-->" +jquery.mybrowser.engine.type+ ":" +jquery.mybrowser.engine.version+ "<br > ");
Document.writeln ("Your browser shell type-->" +jquery.mybrowser.shell.type+ ":" +jquery.mybrowser.shell.version+ "<br>" );
</script>
<body>
<br/> test the type and version of the kernel and shell of the browser:<br/>
</body>