Is it possible to create a link that will open in my application if it is installed, and return to another URL if not?

Users can share files from our application via twitter. Twitter includes a URL that points to our server, which determines whether the user is on a mobile device and redirects the URL using our custom application scheme so that the link opens in our application.

This is great for desktop users and for mobile users who have our application installed; but it does not work for mobile users who do not. So we would like to do this in order to show all users a page containing a link that, when clicked, will open the application using the custom URL scheme, if supported, and open another URL where the user can download our application, if not .

So I'm looking for an answer in HTML or JS that looks something like this:

<a href="ourapp://www.ourdomain.com/files/12345"
   fallbackhref="http://www.ourdomain.com/buyourapp">Click to download</a>

Is it possible? If so, how to do it?

+5
source share
1 answer

You can achieve this in Android using the following code snippet:

function openLink () {
    var appWindow = window.open("ourapp://www.ourdomain.com/files/12345","_blank");
    setTimeout( function () {if (appWindow) {
        appWindow.location ="http://www.ourdomain.com/buyourapp";
            }
            },1000);
}

openLink() ( ).

iOS - , .

iOS : 2 HTML

№1: , / -

<script type="text/javascript">
function openLink (url,customURI) {
    window.open("file2.html?lp="+url+"&customURI="+customURI,"_blank");
}
</script>
<img src="IMAGE SOURCE" onclick="openLink('LANDING PAGE','CUSTOM URI')">

№ 2:

<html>
<script>
function openApp () {
    var start, end, elapsed;
    var params =   window.location.href.split("lp=")[1];
    var url     =   params.split("&customURI=")[0];
    var customURI     =   params.split("&customURI=")[1];
    var time = (new Date()).getTime();
    document.location       =       customURI+url;        
    setTimeout(function(){
            var now = (new Date()).getTime();
            if((now - time)<2550) {
            javascript: console.log(new Date().getTime());
                            document.location = url;
            }
            else{
            window.open('', '_self', '');
                    window.close();
        }
    }, 2000);

}
</script>
<body onload="openApp()">
    <a onclick="openApp()" id="newButton">Click Here to open the App</a>
</body>

, :)

+3

All Articles