Skip to content

Instantly share code, notes, and snippets.

@amitsaxena
Created January 25, 2014 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amitsaxena/8625016 to your computer and use it in GitHub Desktop.
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)
<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
Copy link

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