Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Custom URL: Launch app if app is installed, else open an alternate URL (iOS Safari only)
<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>
@pradeepganapathy

This comment has been minimized.

Copy link

@pradeepganapathy pradeepganapathy commented Mar 15, 2016

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://";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment