网页在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等的检测函数,在此就不一一列举了。希望能抛砖引玉。