0

There are quite a few questions by people looking for code to keep links in standalone apps from opening in Safari on iPhones and iPads. However, I have working code for that already:

if(("standalone" in window.navigator) && window.navigator.standalone){
    var noddy, remotes = false;
        document.addEventListener('click', function(event) {
            noddy = event.target;
                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);
}

This code keeps links on the same hostname from opening in Safari, they open in the full-screen standalone mode as wanted. External links, and links with a _blank target, still open in Safari, as intended.

However, if a link points to another subdomain on our site, those links still open in Safari. I'm trying to figure out a way to supply a "whitelist" to this code, so that those hostnames open in standalone app mode, instead of triggering Safari.

I don't understand this code well enough to know where to make changes to get the result I am looking for.

Sherwin Flight
  • 2,345
  • 7
  • 34
  • 54
  • Tip: Take a look at [this](http://stackoverflow.com/questions/2898740/iphone-safari-web-app-opens-links-in-new-window) question. – Zooza S Oct 10 '15 at 20:06
  • I already have code to keep links inside the app, but links to other subdomains open in Safari. I need the code above to work the same on all subdomains that we have, not just the one the app is running on. – Sherwin Flight Oct 12 '15 at 07:30

0 Answers0