[英]Prevent iOS web app w/ redirect from opening link in mobile Safari
[英]Completely prevent iOS web app from opening link in mobile Safari, even with links containing parameters
我发现了多种解决方案来防止iOS Web应用程序在移动Safari中打开常规链接,但不幸的是,它们不适用于包含参数的链接,例如
href="index.php?s=example"
这些仍在移动Safari中打开。
到目前为止,我在普通堆栈中找到的最短解决方案可以在stackoverflow上找到。 也许有人可以修改该脚本?
尝试4岁的github gist 。 我用它,它的工作原理。 您可以通过bower
使用它:
凉亭安装-保存iosweblinks
可能是页面上出现javascript错误,并且处理程序无法调用?
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.