Skip to content

Instantly share code, notes, and snippets.

@stevef
Created April 27, 2011 13:51
Show Gist options
  • Save stevef/944280 to your computer and use it in GitHub Desktop.
Save stevef/944280 to your computer and use it in GitHub Desktop.
redirect to app store if registered protocol is not available
var iDeviceRedirect = function( url, appPath )
{
if ( url )
{
window.mobileDetected = true;
// for iDevice, we do redirect on document load.
// After redirect, if our script is still running,
// that means that the redirect failed. We then
// show a dialog box asking to download the app
window.onload = function()
{
var noAppMessage = 'You do not seem to have Insider installed, do you want to go download it now?';
MobileDetect.redirect( url );
setTimeout(
function()
{
if ( confirm( noAppMessage ) )
MobileDetect.redirect( appPath );
},
300
);
}
showMobileAppDownload( appPath );
}
}
// here's MobileDetect.redirect, no brain surgery required
var redirect = function( url )
{
try
{
location.href = url;
}
catch(error)
{
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment