Created
May 20, 2014 17:50
-
-
Save colinpetruno/1e2f2c0d3bf39a389ae6 to your computer and use it in GitHub Desktop.
Iphone / Android url scheme redirects
This file contains 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
if (navigator.appVersion.indexOf('iPhone') > -1 || navigator.appVersion.indexOf('iPad') > -1) { | |
// default link here if they do not have the device installed | |
setTimeout(function noapp() { window.location=params.finalDefault; }, 25); | |
/* if they do have the app installed this is the registered url | |
scheme provided by the client, if they dont have this app installed | |
the url will do nothing and thus force the redirect to the default link after 25 ms */ | |
window.location = deepLinks.apple; | |
} | |
// check for android | |
/*else if (navigator.userAgent.indexOf('Android') > -1) { | |
//works slightly different has to do the redirects within an iframe | |
var iframe = document.createElement('iframe'); | |
// hide the iframe so it doesnt show | |
iframe.style.visibility = 'hidden'; | |
// load the scheme | |
iframe.src = deepLinks.android; | |
//if the iframe loads (did not redirect to app), | |
//set the window to default url | |
iframe.onload = function noapp() { window.location=params.finalDefault; }; | |
document.body.appendChild(iframe); | |
} */ | |
//default for non mobile browsers | |
else { | |
// direct to the url | |
window.location=params.finalDefault; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment