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 = '';

  var timeout;
  function preventPopup() {
    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);