如何用js判断是否为iPhone 6 plus中的浏览器


  网页在iPhone 6 plus的浏览器中遇到了一些兼容性的问题,需要针对性的修复。于是需要检查是否为iPhone 6 plus。我根据iPhone 6 plus的屏幕特点,设计了如下判断函数。亲测可用。

1 var isPhone6p = (function(){
2   var h=window.innerHeight,w=window.innerWidth,useragent = navigator.userAgent.toLowerCase(),isP6p = false;
3 
4   if(useragent.match(/mobile/i)!==null && useragent.match(/iphone/i)!==null && ( h>w ? (Math.abs(w-414)<10 && h<=736) : (Math.abs(w-736)<10) && h<=414)) isP6p = true;
5 
6   return isP6p;
7 })();

  同理,我们也可以写出iPhone6、iphone5、iphone4等的检测函数,在此就不一一列举了。希望能抛砖引玉。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM