您的位置:首页 > 移动开发 > IOS开发

Detecting iOS

2015-09-15 11:27 465 查看

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: