<script type=
"text/javascript"
>
/**
* 获取浏览器类型以及版本号
* 支持国产浏览器:猎豹浏览器、搜狗浏览器、傲游浏览器、360极速浏览器、360安全浏览器、
* QQ浏览器、百度浏览器等.
* 支持国外浏览器:IE,Firefox,Chrome,safari,Opera等.
* 使用方法:
* 获取浏览器版本:Browser.client.version
* 获取浏览器名称(外壳):Browser.client.name
* @author:xuzengqiang
* @since :2015-1-27 10:26:11
**/
var Browser=Browser || (function(window){
var document = window.document,
navigator = window.navigator,
agent = navigator.userAgent.toLowerCase(),
IEMode = document.documentMode,
chrome = window.chrome ||
false
,
System = {
agent : agent,
isIE : /msie/.test(agent),
isGecko: agent.indexOf(
"gecko"
)>
0
&& agent.indexOf(
"like gecko"
)<
0
,
isWebkit: agent.indexOf(
"webkit"
)>
0
,
isStrict: document.compatMode ===
"CSS1Compat"
,
supportSubTitle:function(){
return
"track"
in document.createElement(
"track"
);
},
supportScope:function(){
return
"scoped"
in document.createElement(
"style"
);
},
ieVersion:function(){
try
{
return
agent.match(/msie ([d.]+)/)[
1
] ||
0
;
}
catch
(e) {
console.log(
"error"
);
return
IEMode;
}
},
operaVersion:function(){
try
{
if
(window.opera) {
return
agent.match(/opera.([d.]+)/)[
1
];
}
else
if
(agent.indexOf(
"opr"
) >
0
) {
return
agent.match(/opr/([d.]+)/)[
1
];
}
}
catch
(e) {
console.log(
"error"
);
return
0
;
}
},
versionFilter:function(){
if
(arguments.length ===
1
&& typeof arguments[
0
] ===
"string"
) {
var version = arguments[
0
];
start = version.indexOf(
"."
);
if
(start>
0
){
end = version.indexOf(
"."
,start+
1
);
if
(end !== -
1
) {
return
version.substr(
0
,end);
}
}
return
version;
}
else
if
(arguments.length ===
1
) {
return
arguments[
0
];
}
return
0
;
}
};
try
{
System.type = System.isIE?
"IE"
:
window.opera || (agent.indexOf(
"opr"
) >
0
)?
"Opera"
:
(agent.indexOf(
"chrome"
)>
0
)?
"Chrome"
:
window.openDatabase?
"Safari"
:
(agent.indexOf(
"firefox"
)>
0
)?
"Firefox"
:
'unknow'
;
System.version = (System.type ===
"IE"
)?System.ieVersion():
(System.type ===
"Firefox"
)?agent.match(/firefox/([d.]+)/)[
1
]:
(System.type ===
"Chrome"
)?agent.match(/chrome/([d.]+)/)[
1
]:
(System.type ===
"Opera"
)?System.operaVersion():
(System.type ===
"Safari"
)?agent.match(/version/([d.]+)/)[
1
]:
"0"
;
System.shell=function(){
if
(agent.indexOf(
"maxthon"
) >
0
) {
System.version = agent.match(/maxthon/([d.]+)/)[
1
] || System.version ;
return
"傲游浏览器"
;
}
if
(agent.indexOf(
"qqbrowser"
) >
0
) {
System.version = agent.match(/qqbrowser/([d.]+)/)[
1
] || System.version ;
return
"QQ浏览器"
;
}
if
( agent.indexOf(
"se 2.x"
)>
0
) {
return
'搜狗浏览器'
;
}
if
(chrome && System.type !==
"Opera"
) {
var external = window.external,
clientInfo = window.clientInformation,
clientLanguage = clientInfo.languages;
if
( external &&
'LiebaoGetVersion'
in external) {
return
'猎豹浏览器'
;
}
if
(agent.indexOf(
"bidubrowser"
)>
0
) {
System.version = agent.match(/bidubrowser/([d.]+)/)[
1
] ||
agent.match(/chrome/([d.]+)/)[
1
];
return
"百度浏览器"
;
}
if
( System.supportSubTitle() && typeof clientLanguage ===
"undefined"
) {
var storeKeyLen = Object.keys(chrome.webstore).length,
v8Locale =
"v8Locale"
in window;
return
storeKeyLen >
1
?
'360极速浏览器'
:
'360安全浏览器'
;
}
return
"Chrome"
;
}
return
System.type;
};
System.name = System.shell();
System.version = System.versionFilter(System.version);
}
catch
(e) {
console.log(
"error"
);
}
return
{
client:System
};
})(window);
alert(Browser.client.name+
" "
+Browser.client.version);
</script>