App Launcher Link
android -> native browser (non-chrome) -> no app -> web -> yes app -> app -> chrome browser -> no app -> web -> yes app -> app ios -> no app -> web -> yes app -> app other devices -> web
#1: attempt opening custom app URL
Redirecting the device browser to the custom app URL to open app
If the app is install on the device, the custom app URL will trigger the browser to open the app. It is used as a test for app availability.
set the browser location to a custom app url:
someApp://#Intent;scheme=someApp;end /* or */ someApp://
ios: if the app is not installed on the device, safari will display an invalid path error.
android - chrome: if the app is not installed, chrome will display a website not found error for Chrome v.19+
#2: noapp cookie flag
Setting a cookie for flag persistance
Utilize a cookie to signify the app is not installed on the device to minimize the invalid path error on iOS Safari only once.
check noapp cookie true set browser location to web false set timer: web fallback set noapp cookie with expiration set browser location to web attempt custom app url success redirect to app fail (no app redirection) timer complete -> web fallback
If the app is installed on the iPhone, user is redirected out of Safari into the app. If the fallback timer is short, the script continues until the device is completely switched into the app. Therefore, web fallback is triggered and
noapp cookie is set in safari during the app switch. Upon next visit, the user will go straight to
web since the
noapp cookie is set, even though the app is installed.
If the fallback timer is long enough, the script stops executing as soon as the device completely switches into the app, but if the app is not installed on the device, the invalid path error will be more noticeable for a longer time.
#3: pagehide event
pagehide event is triggered when a user gets redirected out of Safari and into the app through custom app URL.
noapp cookie does not get set after app redirect on iOS Safari
appRedirect flag upon
pagehide event trigger.
pagehide event will trigger upon leaving Safari. Then as the web fallback executes,
appRedirect flag is used to skip setting the
pagehide event does not get triggered immediately upon leaving safari. About one second delay into the targeted app before
pagehide event is triggered in safari in the background.
If the fallback timer is short, the web fallback executes before the
pagehide event; the
appRedirect flag in web fallback does not reflect the actual behavior of the app switch.
if the fallback timer is set for more than 1000+ms,
pagehide event can be triggered, but noapp iOS users may see the error popup for a longer period, which makes for an insufficient user experience.
pagehide event delay unreliably varies depending upon the CPU load.
Other Failed Methods
true if the page is in a state considered to be hidden to the user, and
false otherwise. Suggested by an answer on stackoverflow.
website not found error still occured on Chrome
place the custom app URL in the iframe
It doesn't work on Chrome and invalid path error still occurs on iOS.
wrap the custrom app URL redirection in a try/catch.
same symptoms to attempt opening custom app URL
This should be obvious, but ajax is only for
HTTP request, but I thought I should try. So yup,
someApp:// always fails.