Created
January 25, 2014 22:59
-
-
Save amitsaxena/8625016 to your computer and use it in GitHub Desktop.
Custom URL: Launch app if app is installed, else open an alternate URL (iOS Safari only)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
var timer; | |
window.addEventListener("pageshow", function(evt){ | |
clearTimeout(timer); | |
}, false); | |
window.addEventListener("pagehide", function(evt){ | |
clearTimeout(timer); | |
}, false); | |
function launch_app_or_alt_url(el) { | |
lastInterval = getTime(); | |
heartbeat = setInterval(intervalHeartbeat, 200); | |
document.location = 'myapp://customurl'; | |
timer = setTimeout(function () { | |
document.location = 'http://alternate.url.com'; | |
}, 2000); | |
} | |
$(".source_url").click(function(event) { | |
launch_app_or_alt_url($(this)); | |
event.preventDefault(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
When i try this, am getting error as ' Safari cannot open the page because the address is invalid. I have installed the app in iPad. Check my below code.
document.location = "Metro-TV://";