Skip to content

Instantly share code, notes, and snippets.

@trekdemo
Forked from kylebarrow/example.html
Created June 23, 2011 07:13
Show Gist options
  • Save trekdemo/1042081 to your computer and use it in GitHub Desktop.
Save trekdemo/1042081 to your computer and use it in GitHub Desktop.
Prevent links in standalone web apps opening Mobile Safari
// Mobile Safari in standalone mode
if(("standalone" in window.navigator) && window.navigator.standalone){
window.addEventListener("load",function() {
var links = document.getElementsByTagName('a'),
i = link.length - 1;
for ( ;i; i--)
{
// Don't do this for javascript: links
if(links[i].href.toLowerCase().indexOf('javascript') !== 0)
{
links[i].addEventListener("click",function(event){
top.location.href = this.href;
event.returnValue = false;
},false);
}
}
},false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment