首页 > 代码库 > 检测浏览器的特性
检测浏览器的特性
1.检测桌面端浏览器的特性。
$.checkDetect = function() {
var Detect = {
ie: /msie\s*\d+\.\d/gi,
chrome: /chrome\/[\w\.]+(\s)?/gi,
firefox: /firefox\/[\w\.]+(\s)?/gi,
};
var ua = navigator.userAgent.toLowerCase(),
info = {},
match = [];
for (i in Detect) {
match = ua.match(Detect[i]);
if (match) {
info.browser = i;
info.version = match.join(" ").match(/[0-9]+/g).join(".");
}
}
return info;
}
var Detect = {
ie: /msie\s*\d+\.\d/gi,
chrome: /chrome\/[\w\.]+(\s)?/gi,
firefox: /firefox\/[\w\.]+(\s)?/gi,
};
var ua = navigator.userAgent.toLowerCase(),
info = {},
match = [];
for (i in Detect) {
match = ua.match(Detect[i]);
if (match) {
info.browser = i;
info.version = match.join(" ").match(/[0-9]+/g).join(".");
}
}
return info;
}
检测移动端浏览器属性:
checkDetect = function(){
var Detect = {
webkit: /(AppleWebKit)[ \/]([\w.]+)/,
ipad: /(ipad).+\sos\s([\d+\_]+)/i,
windows: /(windows\d*)\snt\s([\d+\.]+)/i,
iphone: /(iphone)\sos\s([\d+\_]+)/i,
ipod: /(ipod).+\sos\s([\d+\_]+)/i,
android: /(android)\s([\d+\.]+)/i
};
var ua = window.navigator.userAgent,
browser = Detect.webkit.exec(ua),
ios = /\((iPhone|iPad|iPod)/i.test(ua),
//["iPhone OS 5_1", "iPhone", "5_1"]
tmp = [],
N = {},
match = [];
for(i in Detect){
match = Detect[i].exec(ua);
if(match){
tmp = Detect[i].exec(ua);
}
}
N = {
system : tmp[1].toLowerCase(),
version : tmp[2].replace(/(\_|\.)/ig, ‘.‘).toLowerCase(),
browser : browser ? browser[1].toLowerCase() : ‘apple/webkit‘,
ios: ios
}
return N;
} var Detect = {
webkit: /(AppleWebKit)[ \/]([\w.]+)/,
ipad: /(ipad).+\sos\s([\d+\_]+)/i,
windows: /(windows\d*)\snt\s([\d+\.]+)/i,
iphone: /(iphone)\sos\s([\d+\_]+)/i,
ipod: /(ipod).+\sos\s([\d+\_]+)/i,
android: /(android)\s([\d+\.]+)/i
};
var ua = window.navigator.userAgent,
browser = Detect.webkit.exec(ua),
ios = /\((iPhone|iPad|iPod)/i.test(ua),
//["iPhone OS 5_1", "iPhone", "5_1"]
tmp = [],
N = {},
match = [];
for(i in Detect){
match = Detect[i].exec(ua);
if(match){
tmp = Detect[i].exec(ua);
}
}
N = {
system : tmp[1].toLowerCase(),
version : tmp[2].replace(/(\_|\.)/ig, ‘.‘).toLowerCase(),
browser : browser ? browser[1].toLowerCase() : ‘apple/webkit‘,
ios: ios
}
return N;
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。