Apple conveniently let’s users add any site to their home screen as a standalone web application that acts much like a native application.
But there’s one problem – by default all links open in Safari rather than in the web application. Very annoying.
I found a few bits of code out there to workaround this issue, the best of which came from Stanislav Kostadinov. Since we use mostly CoffeeScript, here’s a CS version:
# based on http://stanislav.it/how-to-prevent-ios-standalone-mode-web-apps-from-opening-links-in-safari/ | |
if window.navigator.standalone? | |
noddy = false | |
remotes = false | |
document.addEventListener 'click', (event) -> | |
noddy = event.target | |
while noddy.nodeName isnt 'A' and noddy.nodeName isnt 'HTML' | |
noddy = noddy.parentNode | |
if noddy.href? and !!~ noddy.href.indexOf('http') and (!!~ noddy.href.indexOf(document.location.host) || remotes) | |
event.preventDefault() | |
document.location.href = noddy.href | |
return | |
, false |
Reblogged this on jailbr0keni0s's Blog.
I realize this is a very old post and I assume this method worked at the time of posting but any ideas to make this work with iphone 6 + ?
I’ve tested this through iOS 9. Is it not working on iOS 10?