JavaScript判断浏览器和hack滚动条的写法
更新时间:2017年07月23日 14:26:31 投稿:mrr
这篇文章主要介绍了JavaScript判断浏览器和hack滚动条的写法,需要的朋友可以参考下
判断各大浏览器内核:
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isOpera = userAgent.indexOf("Opera") > -1; //判断是否Opera浏览器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge
var?isFF?=?userAgent.indexOf("Firefox")>-1 //判断是否Firefox浏览器??
var?isSafari?=?userAgent.indexOf("Safari")>-1&&?userAgent.indexOf("Chrome")==-1; //判断是否Safari浏览器??
var?isChrome?=?userAgent.indexOf("Chrome")>-1&&?userAgent.indexOf("Edge")==-1; //判断Chrome浏览器??
处理各个浏览器滚动条,以下是我隐藏公司项目中滚动条的写法,仅供参考:
if(isFF){
console.log('火狐')
$('#parent').width((windowWidth -320)*(1.01749));
}else if(isChrome){
console.log('谷歌')
$('#parent').width((windowWidth -320)*(1.01749));
}else if(isIE){
console.log('ie10-ie5')
$('#parent').width((windowWidth -320)*(1.01720));
}else if(isEdge){
console.log('edge')
$('#parent').width((windowWidth -320)*(1.02224));
}else{
console.log('ie11和其他浏览器')
$('#parent').width((windowWidth -320)*(1.01816));
}
以上所述是小编给大家介绍的JavaScript判断浏览器和hack滚动条的写法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
相关文章
基于JavaScript实现继承机制之原型链(prototype chaining)的详解
我们知道在JavaScript中定义类的原型方式,而原型链扩展了这种方式,以一种有趣的方式实现继承机制。prototype 对象是个模板,要实例化的对象都以这个模板为基础。总而言之,prototype 对象的任何属性和方法都被传递给那个类的所有实例。原型链利用这种功能来实现继承机制2013-05-05
Sample script that displays all of the users in a given SQL
Sample script that displays all of the users in a given SQL Server DB...2007-06-06


最新评论