how to prevent iOS safari alert when trying to open non-installed native app?
Here is a solution that works for me:
var timeout;function preventPopup() { clearTimeout(timeout); timeout = null; window.removeEventListener('pagehide', preventPopup);}function openApp() { $('<iframe />') .attr('src', appurl) .attr('style', 'display:none;') .appendTo('body'); timeout = setTimeout(function() { document.location = appstore; }, 500); window.addEventListener('pagehide', preventPopup);}
use iframe.
$('<iframe />').attr('src', "appname://").attr('style', 'display:none;').appendTo('body');
For solving this and avoid no wanted iOS safari alert I've used a different approach handle also an iframe but without jquery and listener events. It works perfectly.
var iframe = document.createElement("iframe"); iframe.style.border = "none"; iframe.style.width = "1px"; iframe.style.height = "1px"; iframe.onload = function () { document.location = alt; }; iframe.src = nativeSchemaUrl; //iOS app schema url window.onload = function(){ document.body.appendChild(iframe); } setTimeout(function(){ window.location = fallbackUrl; //fallback url },300);