Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>UPDATE: Google broke this. See the new accepted answer instead.</p> <p>The key, it turns out, is the document.webkitHidden property. When you set window.location to a custom URL scheme and it opens, the browser keeps running, but that property goes to false. So you can test it to determine whether the custom URL scheme was handled.</p> <p>Here's a sample, which you can <a href="https://s3.amazonaws.com/kaontest/productlink.html" rel="nofollow noreferrer">view live</a></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Starting App...&lt;/title&gt; &lt;script&gt; var URL = "kaonkaon://product.html#malvern;6"; var MARKET = "market://details?id=com.kaon.android.lepton.kaon3d"; var ITUNES = "itms://itunes.apple.com/us/app/kaon-interactive-3d-product/id525051513?mt=8&amp;uo=4"; var QR = "http://goo.gl/gz07g"; // this should be a shortened link back to this page function onLoad() { if (navigator.userAgent.match(/Android/)) { if (navigator.userAgent.match(/Chrome/)) { // Jelly Bean with Chrome browser setTimeout(function() { if (!document.webkitHidden) window.location = MARKET; }, 1000); window.location = URL; } else { // Older Android browser var iframe = document.createElement("iframe"); iframe.style.border = "none"; iframe.style.width = "1px"; iframe.style.height = "1px"; var t = setTimeout(function() { window.location = MARKET; }, 1000); iframe.onload = function () { clearTimeout(t) }; iframe.src = URL; document.body.appendChild(iframe); } } else if (navigator.userAgent.match(/iPhone|iPad|iPod/)) { // IOS setTimeout(function() { if (!document.webkitHidden) window.location = ITUNES; }, 25); window.location = URL; } else { // Not mobile var img = document.createElement("img"); img.src = "https://chart.googleapis.com/chart?chs=300x300&amp;cht=qr&amp;chl="+encodeURIComponent(QR); document.body.appendChild(img); } } &lt;/script&gt; &lt;/head&gt; &lt;body onload="onLoad()"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload