Discover iOS 8 with jQuery

I have googled and many ideas, but they either confuse the whole site in all browsers, either they are really old, or they are javascript and not jQuery. I'm exhausted.

This currently works for iOS detection, but not for version:

$(document).ready(function() { var deviceAgent = navigator.userAgent.toLowerCase(); var agentID = deviceAgent.match(/(iphone|ipod|ipad)/); if (agentID) { ... do something here } }); 

How can I add only iOS 8 detection inside this, so I can just create the html class "ios-8" "no-ios8" or the equivalent.

+5
source share
1 answer

The Mobile Safari UA variable looks like this:

Mozilla / 5.0 (iPhone, iPhone for iPhone OS 8_0_2, like Mac OS X) AppleWebKit / 600.1.4 (KHTML, for example, Gecko) Version /8.0 Mobile / 12A405 Safari / 600.1.4

(Source: http://whatsmyuseragent.com/ )

So you can write such a function. ( DEMO )

 var isIOS8 = function() { var deviceAgent = navigator.userAgent.toLowerCase(); return /(iphone|ipod|ipad).* os 8_/.test(deviceAgent); } alert("isIOS8: " + isIOS8()); 

Visit the demo page in the Safari mobile browser or in a webview application such as iOS Chrome to see its true alerts.

+13
source

Source: https://habr.com/ru/post/1204652/


All Articles