史上最强大的浏览器嗅探

  在前端开发中经常会遇到一系列兼容性问题,怎样精准地识别出各个浏览器的版本是一件很头痛的问题,尤其是navigator有可能被厂商伪造的情况。虽然大神们建议要针对浏览器特性来处理而不是通过浏览器版本,但是实际操作过程中却有相当大的困难。

  以下是大神们总结的各种浏览器嗅探的办法,亲测无误

IE篇:

ie=!!window.VBArray
ie678=!+"\v1"; ie678=!-[1,]; ie678='\v'=='v'; ie678=('a-b'.split(/(~)/))[1]=="b" ie678=0.9.toFixed(0)=="0" ie678=/\w/.test('\u0130') ie8=window.toStaticHTML ie9=window.msPerformance ie678=0//@cc_on+1; ie67=!"1"[0] ie8=!!window.XDomainRequest; ie9=document.documentMode&&document.documentMode===9; ie10 = window.navigator.msPointerEnabled; ie11 = !!window.MSInputMethodContext;

Firefox篇:

firefox=!!window.netscape;
firefox=!!window.updateCommands;
safari=window.openDatabase&&!window.chrome;
chrome=!!(window.chrome&&window.google);

移动设备篇:

iphone=/iphone/i.test(navigator.userAgent);
iphone4=window.devicePixelRatio>=2;
ipad=/iPad/i.test(navigator.userAgent);
android=/android/i.test(navigator.userAgent);
IOS=iphone||ipad;

 

转载于:https://www.cnblogs.com/lingtong/p/4156807.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值