【发布时间】:2013-04-13 12:31:03
【问题描述】:
此脚本可防止在 Mobile Safari 中打开链接。这适用于 Web 应用在 iOS 上处于应用模式时(主屏幕书签)。
if(("standalone" in window.navigator) && window.navigator.standalone){
// If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true
var noddy, remotes = false;
document.addEventListener('click', function(event) {
noddy = event.target;
// Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML
while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") {
noddy = noddy.parentNode;
}
if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes))
{
event.preventDefault();
document.location.href = noddy.href;
}
},false);
}
我的问题是如何让上面的脚本忽略与类的链接?
例如,我有 a.lightbox - 使用 www.photoswipe.com jquery 插件打开此链接并在灯箱中显示图像。
但是当我使用脚本时,它会终止灯箱启动,它只会自行打开图像。但如果我使用上面的这个脚本,photoswipe 灯箱就可以正常工作。
有没有人有一些建议或帮助修改此脚本以忽略这些链接a.lightbox
谢谢 乔什
【问题讨论】:
标签: javascript jquery iphone web-applications