0

I'm using the following javascript in my application.html.erb to allow my web app to behave like an iOS app when saved from Safari to the home screen. This script prevents links in the app from opening in Safari:

<script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>

It works great and when the app is saved to my home screen, all navigation works as expected except the 'Sign out' button, which errors out:

"The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved."

This does not occur when I access the web app from Safari instead of the home screen, and then I tap the 'Sign out' button—it behaves as expected and signs the user out (destroying the session via the 'delete' method).

Any thoughts what part of the javascript might be causing this error or how I can go about fixing this would be appreciated.

stewartm
  • 179
  • 1
  • 2
  • 10

1 Answers1

0

It's a bit hard to follow a minimized script, but I'll bite.

The script looks like it was meant to stop links from working normally, using javascript redirect document.location.href=clicked_link.href instead.

Wild guess: your "logout" link is served using https protocol, but this scrpt redirects without changing the protocol. Or, maybe, it's not really a link, but something like <a href="javascript:void(0)"> with an event listener in which case document.location=javascript:void(0) and boom, page not found.

pawel
  • 35,827
  • 7
  • 56
  • 53
  • Thanks for your answer Pawel. I don't think my link uses https protocol, so that's probably not the issue. Also, it is a link, '/signout', which normally maps to a Rails DELETE method (i.e., match '/signout', to: 'sessions#destroy', via: :delete). Anyway, I'm going to check with my front-end guy at work tomorrow. Will update when I've more info. Thanks again! – stewartm Sep 24 '13 at 06:32