以下一段代码用于判断当前浏览器以及版本号,以此做一些操作,例如不支持此浏览器,或者浏览器版本不够等等
// ie10及以下浏览器跳转
navigator.sayswho= (function(){
var ua= navigator.userAgent, tem,
M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+)/g.exec(ua) || []
return 'IE '+(tem[1] || '')
}
if(M[1]=== 'Chrome'){
tem= ua.match(/\b(OPR|Edge)\/(\d+)/)
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera')
}
M= M[2]? [M[1], M[2]]: [navigator.appName, navigator.appVersion, '-?']
if((tem= ua.match(/version\/(\d+)/i))!= null) M.splice(1, 1, tem[1])
return M.join(' ');
})();
var userAgent = navigator.sayswho.split(' ')[0]
var version = +navigator.sayswho.split(' ')[1]
switch(userAgent) {
case 'Ie':
// ie 10以下跳转
if (version < 10) handleLowVerBro()
break
case 'Firefox':
// 火狐 43以下跳转
if (version < 43) handleLowVerBro()
}
// 跳转的路径
function handleLowVerBro () {
this.location.href = '******'
}
附带navigator对象的文档,navigator对象包含浏览器的信息,此对象所有浏览器都支持