title: Redirect to Android App from a Website?
body: <p>When a user opens a website I want one of the following two cases to be happen:</p>
  
  <ol>
  <li>If the app mycoolapp is installed redirect the user to the app using the custom url scheme mycoolapp://</li>
  <li>If the app is not installed stay on the current page without posting or redirecting to an unknown page or an error popup.</li>
  </ol>
  
  <p>Case 1 is easy you can use the following code: </p>
  
  <pre><code>window.location = "mycoolapp://"; 
  </code></pre>
  
  <p>This will work if the app is installed on the device. When the app is not installed it redirects the user to a blank page which is unknown. </p>
  
  <p>For case 2 I have a solution using an iFrame which works great on iOS and on the native Android browser. It does not work on Chrome for Android. </p>
  
  <pre><code>var redirect = function (location) {
      var iframe = document.createElement('iframe');
      iframe.setAttribute('src', location);
      iframe.setAttribute('width', '1px');
      iframe.setAttribute('height', '1px');
      iframe.setAttribute('position', 'absolute');
      iframe.setAttribute('top', '0');
      iframe.setAttribute('left', '0');
      document.documentElement.appendChild(iframe);
      iframe.parentNode.removeChild(iframe);
      iframe = null;
  };    
  
  redirect('mycoolapp://');
  </code></pre>
  
  <p>When the app is installed it is working on the native Android browser, but on Chrome for Android there is not redirect. Nothing happens on the page. </p>
  
  <p><strong>How can I make redirect to my app working on Chrome for Android without redirecting to a blank page when the app is not installed?</strong></p>
  
  <p><strong>Edit:</strong> I know that you can use an Intent </p>
  
  <pre><code>window.location = "intent://#Intent;package=com.mycoolapp;scheme=mycoolapp;launchFlags=268435456;end;";
  </code></pre>
  
  <p>This is not what I want because it launches the app page on google play if the app is not installed. Is there a way that it will not redirect to google play?</p>