JavaScript的浏览器检查 [英] Javascript check browser
本文介绍了JavaScript的浏览器检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
没有任何人有一个脚本用于检查旧的浏览器。它必须遵循这一标准:
-
允许火狐3.6或向上
-
允许谷歌浏览器15和高达
-
允许Safari 5的涨幅高达
-
阻止IE和Opera
-
阻止所有其他浏览器
解决方案
您可以使用导航
对象这一点,在你可以使用的userAgent
属性像
如果(navigator.userAgent.indexOf('火狐')= -1&安培;!&安培; parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('火狐') + 8))> = 3.6){//火狐
//允许
}否则如果(navigator.userAgent.indexOf('铬')= -1&安培;!&安培; parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('铬')+ 7).split('')[ 0])> = 15){//浏览器
//允许
}否则如果(navigator.userAgent.indexOf('Safari浏览器')= -1&安培;!&安培;!navigator.userAgent.indexOf('版本')= -1&放大器;&安培; parseFloat(navigator.userAgent.substring(领航员。 userAgent.indexOf('版本')+ 8).split('')[0])> = 5){//野生
//允许
}其他{
//块
}
does anyone have a script for checking for old browsers. It would have to follow this criteria:
Allow firefox 3.6 or up
Allow Google Chrome 15 and up
Allow Safari 5 or up
Block IE and opera
Block all other browsers
解决方案
You can use navigator
object for this and in that you can use userAgent
property like
if (navigator.userAgent.indexOf('Firefox') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Firefox') + 8)) >= 3.6){//Firefox
//Allow
}else if (navigator.userAgent.indexOf('Chrome') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Chrome') + 7).split(' ')[0]) >= 15){//Chrome
//Allow
}else if(navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Version') != -1 && parseFloat(navigator.userAgent.substring(navigator.userAgent.indexOf('Version') + 8).split(' ')[0]) >= 5){//Safari
//Allow
}else{
// Block
}
这篇关于JavaScript的浏览器检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文