title: Create a fallback URL if app is not installed using javascript
body: <p>I'm attempting to make a plugin that converts normal links into deep links when a user is browsing on an Android or iOS device. So, for example, it finds the link and replaces it with the deep link like this:</p>
  
  <pre><code>var facebookURL  = $('[href*="facebook.com"]');
  var facebookDeep = 'fb://profile/123456789';
  $(facebookURL).attr('href', facebookDeep);
  </code></pre>
  
  <p>When the link is clicked and Facebook is installed, the link will open up the Facebook app. If Facebook isn't installed, however, when the link is clicked, nothing happens. So I figured that I would just automatically open the web URL if there was still a focus on the frame after 1000ms:</p>
  
  <pre><code>$($(facebookURL)).click(function(){
    setTimeout(function(){
      if ($(this).is(":focus")) {
        location.href = 'https://facebook.com';
      } else {
        console.log('Focus was lost');
      }
    }, 1000);
  });
  </code></pre>
  
  <p>But this logs <em>Focus was lost</em>.</p>
  
  <p>Any ideas on another way I can accomplish this? Or if there's an easier way to create a fallback.</p>