Is there an event in mobile safari that can detect when a page is hidden due to a redirect? I want to open my app directly if it's installed, try Facebook if it's installed, and go to the webpage for that id if neither are available.
- If 'myapp' is installed, open myapp. The safari tab still redirects to facebook.com
- If 'myapp' is not installed, but Facebook is, open the Facebook iOS app. The safari tab still redirects to facebook.com
I've set up a test link with the following HTML/JS:
<!DOCTYPE html>
<html>
<head>
<title>Redirect Test</title>
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'></script>
<meta name='viewport' content='initial-scale = 1.0,maximum-scale = 1.0' />
</head>
<body>
<button>Open Oreo</button>
<script type='text/javascript'>
jQuery(function(){
jQuery( 'button' ).on( 'click', function(){
var myid = null, fbid = null;
// Watch for page leave to kill timers
jQuery( window ).on( 'pagehide pageshow blur unload', function(){
if ( myid ) {
clearTimeout( myid );
}
if ( fbid ) {
clearTimeout( fbid );
}
});
window.location = "myapp://fbprofile/oreo";
var myid = setTimeout(function(){
// My app doesn't exist on device, open Facebook
window.location = "fb://profile/oreo";
fbid = setTimeout(function(){
// Facebook doesn't exist on device, open Facebook mobile
window.location = "https://www.facebook.com/oreo";
}, 100);
}, 100);
});
});
</script>
</body>
</html>