1 . 获取谷歌浏览器版本
function getChromeVersion() {
var arr = navigator.userAgent.split(' ');
var chromeVersion = '';
for(var i=0;i < arr.length;i++){
if(/chrome/i.test(arr[i]))
chromeVersion = arr[i]
}
if(chromeVersion){
return Number(chromeVersion.split('/')[1].split('.')[0]);
} else {
return false;
}
}
if(getChromeVersion()) {
var version = getChromeVersion();
if(version < 56) {
alert('浏览器版本过低,为了正常显示请将浏览器升级到最新版本!');
}
}
- 获取浏览器类型和版本
function getBroswerAndVersion(){
var agent = navigator.userAgent.toLowerCase() ;
var reg_ie = /msie [\d.]+;/gi ;
var reg_ff = /firefox\/[\d.]+/gi
var reg_chrome = /chrome\/[\d.]+/gi ;
var reg_saf = /safari\/[\d.]+/gi ;
var reg_version = /\d+/gi ;
//IE11以下
if(agent.indexOf("msie") > 0)
{
var info = agent.match(reg_ie)[0];
var version = info.match(reg_version)[0];
return {type:"IE",version:version,isMatch:parseInt(version)>=9,update:9}
}
//IE11版本中不包括MSIE字段
if(agent.indexOf("trident") > 0&&agent.indexOf("rv") > 0){
//return "IE " + agent.match(/rv:(\d+\.\d+)/) [1];
var version = agent.match(/rv:(\d+\.\d+)/)[1];
return {type:"IE",version:version,isMatch:parseInt(version)>=14,update:14}
}
//firefox
if(agent.indexOf("firefox") > 0)
{
//return agent.match(reg_ff) ;
var info = agent.match(reg_ff)[0];
var version = info.match(reg_version)[0];
return {type:"firefox",version:version,isMatch:parseInt(version)>=54,update:54}
}
//Chrome
if(agent.indexOf("chrome") > 0)
{
//return agent.match(reg_chrome) ;
//console.log(agent.match(reg_chrome));
var info = agent.match(reg_chrome)[0];
var version = info.match(reg_version)[0];
return {type:"chrome",version:version,isMatch:parseInt(version)>=58,update:58};
}
//Safari
if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0)
{
//return agent.match(reg_saf) ;
var info = agent.match(reg_saf)[0];
var version = info.match(reg_version)[0];
return {type:"safari",version:version,isMatch:parseInt(version)>=10,update:10};
}
}