【问题标题】:Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters完全防止 iOS Web 应用在移动 Safari 中打开链接,即使链接包含参数
【发布时间】:2014-12-17 16:14:56
【问题描述】:

我找到了多种解决方案来阻止 iOS 网络应用在移动 Safari 中打开正常链接,不幸的是它们不适用于包含参数的链接,例如

href="index.php?s=example"

这些仍然在移动 Safari 中打开。

到目前为止我发现的正常链接的最短解决方案可以找到here at stackoverflow。也许有人可以修改那个脚本?

【问题讨论】:

标签: ios parameters mobile-safari iphone-standalone-web-app


【解决方案1】:

试试 4 岁的 github gist。我使用它并且它有效。 您可以通过bower使用它:

凉亭安装 --save iosweblinks

可能是您在页面上有 javascript 错误并且处理程序没有调用?

附:我修改后的脚本,用于防止在standalone 模式下在 Safari 中打开链接:

(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));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多