<html>
<head>
    <script language="javascript">
        try {
            setTimeout(function() {
                alert("App not installed");
                // window.location = "handleme://";
            }, 25);
            window.location = "handleme://";
        }
        catch (e) {
            alert("Error: " + e);
        }
    </script>
</head>
<body>
    <h1>App Detection</h1>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv='cache-control' content='no-cache'>
    <meta http-equiv='expires' content='0'>
    <meta http-equiv='pragma' content='no-cache'>
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <script language="javascript">
        try {
            var appLaunchURL = 'handleme://';
            // var appDownloadURL = 'https://itunes.apple.com/us/app/kaiser-permanente/id493390354?mt=8';
            // var appDownloadURL = 'http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=493390354';
            var appDownloadURL = 'itms-apps://itunes.apple.com/app/id493390354';

            //
            // Window.open
            //
            var before = new Date().valueOf();
            setTimeout(function () {
                //if (new Date().valueOf() - before > 100) return;
                // alert("App not installed");
                window.location = appDownloadURL;
            }, 25);

            //
            // AJAX
            //
            // var request = new XMLHttpRequest();
            // request.open('GET', appLaunchURL, false);
            // request.setRequestHeader("Origin", window.location);
            // request.send();

            window.location = appLaunchURL;
            // launchapp();
        }
        catch (e) {
            alert("Error: " + e);
            // window.location = appDownloadURL;
        }

        function launchapp() {
            // window.location = appLaunchURL;
            // window.location.href = appLaunchURL;
            // var win = window.open(appLaunchURL, "_self");
            // alert(win);
        }
    </script>
</head>
<body>
    <h1>App Detection</h1>
    <br>
    <br>
    <br>
    <br>
    <br>
    <a href="javascript:launchapp();">handleme</a>
</body>
</html>

Change download URL to use itms-apps scheme which seems to bring up the app store faster
Change download URL to use itms-apps scheme which seems to bring up the app store faster
