完全阻止iOS Web应用程序打开移动Safari中的链接,即使包含参数的链接也是如此 [英] Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters

查看:93
本文介绍了完全阻止iOS Web应用程序打开移动Safari中的链接,即使包含参数的链接也是如此的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了多种解决方案来阻止iOS Web应用程序在移动Safari中打开普通链接,但不幸的是,它们不适用于包含参数的链接,例如

I have found multiple solutions to prevent an iOS web app from opening normal links in mobile Safari, unfortunately they do not work for links containing parameters, e.g.

href="index.php?s=example"

这些仍在移动Safari中打开.

These are still opened in mobile Safari.

到目前为止,我找到的最普通链接的最短解决方案可以找到

The shortest solution for normal links I have found thus far can be found here at stackoverflow. Maybe someone can modify that script?

推荐答案

尝试4岁 github gist .我用它,它的工作原理. 您可以通过 bower :

Try 4 years old github gist. I used it and it works. You can use it by bower:

bower install-保存iosweblinks

bower install --save iosweblinks

可能页面上出现JavaScript错误,并且处理程序无法调用吗?

May be you have javascript errors on page and handlers do not call?

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

P.S. My modified script for prevent opening links in Safari in standalone mode:

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

这篇关于完全阻止iOS Web应用程序打开移动Safari中的链接,即使包含参数的链接也是如此的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆