码迷,mamicode.com
首页 > 移动开发 > 详细

Detecting iOS

时间:2015-09-15 12:42:47      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

Detecting iOS

I am not a fan of User Agent sniffing, but here is how you would do it:

var iOS = /iPad|iPhone|iPod/.test(navigator.platform);

Another way, relying on the userAgent:

var iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;

iOS will be either true or false

Why not MSStream

Microsoft injected the word iPhone in IE11‘s userAgent in order to try and fool Gmail somehow. Therefore we need to exclude it. More info about this here and here.

Below is IE11‘s updated userAgent (Internet Explorer for Windows Phone 8.1 Update):

Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 930) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537

Detecting iOS

标签:

原文地址:http://www.cnblogs.com/sban/p/4809739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!