Detect if device is iOS

前端 未结 17 1895
一整个雨季
一整个雨季 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:14

    In my case the user agent was not good enought since in the Ipad the user agent was the same as in Mac OS, therefore I had to do a nasty trick:

    var mql = window.matchMedia("(orientation: landscape)");
    
    /**
     * If we are in landscape but the height is bigger than width
     */
    if(mql.matches && window.screen.height > window.screen.width) {
        // IOS
    } else {
        // Mac OS
    }
    

提交回复
热议问题