var clickedAt = +new Date(), timeout, iframe, webURI, nativeURI; // '+newDate()' is the equivalent of calling valueOf method // of the Date Object. + is a unary operator. // see: http://xkr.us/articles/javascript/unary-add/ if (navigator.userAgent.match(/Android/)) { // Jelly Bean with Chrome browser if (navigator.userAgent.match(/Chrome/)) { // Jelly Bean with Chrome browser setTimeout(function () { if (+new Date() - clickedAt < 3000) { // window.open( url , '_blank' ); window.location = webURI; } }, 2000); window.location = nativeURI; } else { // Older Android browser iframe = document.createElement("iframe"); iframe.style.border = "none"; iframe.style.width = "1px"; iframe.style.height = "1px"; timeout = setTimeout(function () { // window.open( webURI , '_blank' ); window.location = webURI; }, 1000); iframe.onload = function () { clearTimeout(timeout); }; iframe.src = nativeURI; document.body.appendChild(iframe); } } else if (navigator.userAgent.match(/iPhone|iPad|iPod/)) { // IOS timeout = setTimeout(function () { if (+new Date() - clickedAt < 3000) { window.location = webURI; } }, 2000); clearTimeout(timeout); window.location = nativeURI; } else { window.open(webURI, '_blank'); }