Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent iOS safari alert when trying to open non-installed native app?

I've been looking for a way to open a native iOS app from the browser. I found a decent solution here: Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?

This solution works great when you have the app installed. but when a user doesn't have this app installed - safari fires an error message which says "Safari cannot open the page because the address is invalid."

Is there a way to prevent this behaviour and instead to prompt the user to download the app?

like image 461
Dima Feldman Avatar asked Oct 31 '13 08:10

Dima Feldman


People also ask

How do I stop Safari from jumping apps?

Turn on Restrictions from Settings > General > Restrictions and set a passcode. Scroll down, go to Apps and tap Don't Allow Apps. This will hide all apps you've installed, including LinkedIn. Switch to or open Mobile Safari, use the links and stay within Mobile Safari.


1 Answers

Here is a solution that works for me:

var timeout;  function preventPopup() {     clearTimeout(timeout);     timeout = null;     window.removeEventListener('pagehide', preventPopup); }  function openApp() {         $('<iframe />')     .attr('src', appurl)     .attr('style', 'display:none;')     .appendTo('body');      timeout = setTimeout(function() {             document.location = appstore;     }, 500);     window.addEventListener('pagehide', preventPopup); }  
like image 126
ElizaS Avatar answered Sep 21 '22 00:09

ElizaS