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.