(function(){ document.addEventListener('click', function(e){ const a = e.target.closest('a'); if(!a) return; const href = a.href; if(!href || !/^https?:\/\//i.test(href)) return; // Skip if data-no-chrome if(a.dataset.noChrome !== undefined) return; e.preventDefault(); const ua = navigator.userAgent || ''; // Android if(/Android/i.test(ua)){ const stripped = href.replace(/^https?:\/\//i, ''); const intent = 'intent://' + stripped + '#Intent;scheme=https;package=com.android.chrome;S.browser_fallback_url=' + encodeURIComponent(href) + ';end'; window.location = intent; return; } // iOS if(/iPhone|iPad|iPod/i.test(ua)){ const chromeSecure = href.replace(/^https?:\/\//i, 'googlechromes://'); const chrome = href.replace(/^https?:\/\//i, 'googlechrome://'); window.location = chromeSecure; setTimeout(()=>{ window.location = chrome; }, 500); setTimeout(()=>{ window.location = href; }, 1200); return; } // Desktop fallback window.open(href, '_blank'); }, false); })();
My WordPress Blog