Created
January 27, 2015 17:42
-
-
Save ben-ng/a224d090d37930f2e91a to your computer and use it in GitHub Desktop.
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
(function phoneGapRedirect(){ | |
// No infinite loopdeloops using this querystring | |
if(window.originalLocation.indexOf('no_redirect') > -1) return | |
// Only do this on iPhone OR YOU WILL PISS EVERYONE ON DESKTOP OFF WITH PROTOCOL ERRORS | |
// Also don't do this in homescreened apps OR YOU WILL PISS EVERYONE OFF WITH REDIRECTS | |
if ((/iphone|ipod|ipad/gi).test(navigator.platform) && !navigator.standalone) { | |
var redirect = function (location) { | |
// don't use jquery here b/c it's not a global | |
var iframe = document.createElement('iframe') | |
iframe.setAttribute('src', location) | |
iframe.style.width = '1px' | |
iframe.style.height = '1px' | |
document.body.appendChild(iframe) | |
} | |
// Open the website in the browser after the user switches away to the native app | |
setTimeout(function () { | |
window.location = window.originalLocation.replace(/\/app/,'/app?no_redirect') | |
}, 700) | |
// Open the native app | |
redirect('getable://' + window.originalLocation.slice(window.originalLocation.indexOf('#') + 1)) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment