Detect if device is iOS

前端 未结 17 1827
一整个雨季
一整个雨季 2020-11-22 01:39

I\'m wondering if it\'s possible to detect whether a browser is running on iOS, similar to how you can feature detect with Modernizr (although this is obviously device detec

17条回答
  •  天涯浪人
    2020-11-22 02:23

    In order to detect the iOS version, one has to destructure the user agent with a Javascript code like this:

     var res = navigator.userAgent.match(/; CPU.*OS (\d_\d)/);
        if(res) {
            var strVer = res[res.length-1];
            strVer = strVer.replace("_", ".");
            version = strVer * 1;
        }
    

提交回复
热议问题