When a user opens a website, I need one of the following two cases:
- If mycoolapp is installed, it will redirect the user to the application using the custom mycoolapp URL scheme: //
- If the application is not installed, remain on the current page without publishing or redirecting to an unknown page or pop-up with an error.
Case 1 easily you can use the following code:
window.location = "mycoolapp://";
This will work if the application is installed on the device. When the application is not installed, it redirects the user to a blank page that is unknown.
For case 2, I have a solution using iFrame that works fine on iOS and in my native Android browser. It does not work in Chrome for Android.
var redirect = function (location) { var iframe = document.createElement('iframe'); iframe.setAttribute('src', location); iframe.setAttribute('width', '1px'); iframe.setAttribute('height', '1px'); iframe.setAttribute('position', 'absolute'); iframe.setAttribute('top', '0'); iframe.setAttribute('left', '0'); document.documentElement.appendChild(iframe); iframe.parentNode.removeChild(iframe); iframe = null; }; redirect('mycoolapp://');
When the application is installed, it works in the native Android browser, but there is no redirection in Chrome for Android. Nothing happens on the page.
How can I redirect an application to Chrome for Android without redirecting to a blank page when the application is not installed?
Edit: I know you can use intention
window.location = "intent://#Intent;package=com.mycoolapp;scheme=mycoolapp;launchFlags=268435456;end;";
This is not what I want, because it launches the application page in google play if the application is not installed. Is there a way to prevent it from being redirected to a Google game?