Last active
January 3, 2016 17:09
-
-
Save MichaelWhi/8494381 to your computer and use it in GitHub Desktop.
JavaScript Snippet to be put at bottom of the body, which will fix links including rails UJS links for WebApps ran from the iOS home screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(("standalone" in window.navigator) && window.navigator.standalone){ | |
var noddy, remotes = false; | |
var iosClickFixer = 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 && noddy.getAttribute("data-method") !== "post" && noddy.getAttribute("data-method") !== "delete" || remotes)) | |
{ | |
event.preventDefault(); | |
if(typeof(Turbolinks) !== "undefined"){ | |
Turbolinks.visit(noddy.href); | |
} else { | |
document.location.href = noddy.href; | |
} | |
} | |
}; | |
document.addEventListener('click', iosClickFixer,false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment