Detect if iOS is using webapp

后端 未结 2 1264
醉酒成梦
醉酒成梦 2021-02-07 07:06

I was wondering if it\'s possible to detect if an iOS user is using the webapp, or just visiting the normal way with safari browser.

The reason I want to achieve is tha

相关标签:
2条回答
  • 2021-02-07 07:29

    You have to detect this by using some javascript:

    <script>
    if (("standalone" in window.navigator) &&       // Check if "standalone" property exists
        window.navigator.standalone){               // Test if using standalone navigator
    
        // Web page is loaded via app mode (full-screen mode)
        // (window.navigator.standalone is TRUE if user accesses website via App Mode)
    
    } else {
    
        // Web page is loaded via standard Safari mode
        // (window.navigator.standalone is FALSE if user accesses website in standard safari)
    }
    </script>
    </head> 
    

    Now the extra check "standalone" in window.navigator is needed because some browsers do not have the standalone property and you don't want your code to crash for those browsers.

    0 讨论(0)
  • 2021-02-07 07:32

    iOS and Chrome WebApp behaves different, thats the reason i came to following:

    isInWebAppiOS = (window.navigator.standalone == true);
    isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches);
    
    0 讨论(0)
提交回复
热议问题