Make Better Things



I like to make better things.

How to check if URL scheme is supported in iOS Safari using javascript?

There is no straight forward way to check if URL scheme is supported or not, but we can use a workaround, we can check if our page has a focus after a short timeout. We can use “pagehide” event.

var appurl = 'custom://url';
  var appstore = 'https://itunes.apple.com/us/app/your-app';

  var timeout;
  function preventPopup() {
    clearTimeout(timeout);
    timeout = null;
    window.removeEventListener('pagehide', preventPopup);
  }
  function startApp() {
    document.location = appurl;
    timeout = setTimeout(function(){
      if(confirm('You do not seem to have the App installed, do you want to go download it now?')){
        document.location = appstore;
      }
    }, 1000);
    window.addEventListener('pagehide', preventPopup);
  }

Category: Javascript

Tagged: ,

One Response

  1. igor says:

    it does not work on iOS8

Leave a Reply