How to Prevent iOS Standalone Mode Web Apps From Opening Links in Safari (CoffeeScript Version)

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
if window.navigator.standalone?
noddy = false
remotes = false
document.addEventListener 'click', (event) ->
noddy =
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( || remotes)
document.location.href = noddy.href
, false

view raw
hosted with ❤ by GitHub