Reputation: 3853
This script prevents links from opening in Mobile Safari. This is for when the web app is in app mode on iOS (home screen bookmark).
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);
}
My question is how do you get this script above to ignore links with a class?
So for example I've a.lightbox
- and this link opens and image in a lightbox using the www.photoswipe.com jquery plugin.
But when I use the script it kills the lightbox launch up and it just opens the image on its own. But if I this script above, the photoswipe lightbox works fine.
Has anyone got some suggestions or help modifiy this script to ignore these links a.lightbox
Thanks Josh
Upvotes: 1
Views: 648
Reputation: 46
If you're using jQuery you should be able to just add && !$(noddy).hasClass('lightbox')
to your if test.
Upvotes: 1