Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect if iOS is using webapp

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 that on a iOS webapp when a user click on a link, he will get redirected to the Safari browser. So I'm using the following workaround to make him stay in the webapp(prevent the switching to safari browser).

$( document ).on("click",".nav ul li a",
        function( event ){

        // Stop the default behavior of the browser, which
        // is to change the URL of the page.
        event.preventDefault();

        // Manually change the location of the page to stay in
        // "Standalone" mode and change the URL at the same time.
        location.href = $( event.target ).attr( "href" );

        }
    );

But I want this workaround only to happen when the user is using the webapp, I want it to be conditional for webapp users. So not on the default safari browser.

like image 911
koningdavid Avatar asked Aug 01 '13 09:08

koningdavid


People also ask

How can I check if an app is installed from a Web page on an iPhone?

Show activity on this post. iOS Safari has a feature that allows you to add a "smart" banner to your webpage that will link either to your app, if it is installed, or to the App Store. You do this by adding a meta tag to the page.

Is it possible to check with my website if an app is installed?

Your website can check if your Android app is installed.

How do you detect if the user is using an iPhone Android or a browser?

To detect if browser is running on an Android or iOS device with JavaScript, we check the user agent. const isMobile = { android() { return /Android/i. test(navigator. userAgent); }, iOS() { return /iPhone|iPad|iPod/i.


1 Answers

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.

like image 53
Jean-Paul Avatar answered Sep 30 '22 19:09

Jean-Paul