完全阻止iOS Web应用程序打开移动Safari中的链接,即使包含参数的链接也是如此 [英] Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters
问题描述
我发现了多种解决方案来阻止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屋!