-->

完全防止iOS的Web应用程序在移动Safari中打开链接,即使是含有参数的链接(Completel

2019-10-21 10:41发布

我已经找到了多种解决方案,以防止在iOS web应用程序从打开移动Safari浏览器的正常联系,遗憾的是他们不含有参数的链接,例如工作

href="index.php?s=example"

这些都还是在移动Safari浏览器打开。

正常链接我迄今发现的最短的解决方案,可以发现这里的计算器 。 也许有人可以修改脚本?

Answer 1:

尝试4岁GitHub的要点 。 我用它和它的作品。 您可以使用它bower

亭子安装--save iosweblinks

可能是你网页上的JavaScript错误和处理程序不叫?

PS我为防止打开链接在Safari中修改脚本standalone模式:

(function (standalone) {

    if (!standalone) {
        return;
    }

    document.addEventListener('click', function (e) {
        var element = e.target,
            href = '';

        while (!/^(a|html)$/i.test(element.nodeName)) {
            element = element.parentNode;
        }

        if (element.getAttribute) {
            href = element.getAttribute('href');

            if ('' !== href && '#' !== href && null !== href && (!element.protocol || element.protocol !== 'tel:')) {
                e.preventDefault();
                window.location = element.href;
            }
        }
    }, false);

}(window.navigator.standalone));


文章来源: Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters