独立的Web应用程序链接脚本 – 阻止它附加具有特定类的链接?

此脚本可防止在Mobile Safari中打开链接。 这适用于iOS应用程序模式(主屏幕书签)上的Web应用程序。

gist.github.com/1042026

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

谢谢乔希

如果你正在使用jQuery,你应该只需要在你的if测试中添加&& !$(noddy).hasClass('lightbox')