[英]Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters
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, eg 我发现了多种解决方案来防止iOS Web应用程序在移动Safari中打开常规链接,但不幸的是,它们不适用于包含参数的链接,例如
href="index.php?s=example"
These are still opened in mobile Safari. 这些仍在移动Safari中打开。
The shortest solution for normal links I have found thus far can be found here at stackoverflow . 到目前为止,我在普通堆栈中找到的最短解决方案可以在stackoverflow上找到。 Maybe someone can modify that script?
也许有人可以修改该脚本?
Try 4 years old github gist . 尝试4岁的github gist 。 I used it and it works.
我用它,它的工作原理。 You can use it by
bower
: 您可以通过
bower
使用它:
bower install --save iosweblinks
凉亭安装-保存iosweblinks
May be you have javascript errors on page and handlers do not call? 可能是页面上出现javascript错误,并且处理程序无法调用?
PS My modified script for prevent opening links in Safari in standalone
mode: PS我修改的脚本,用于防止以
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.