Skip to content

Instantly share code, notes, and snippets.

@Vadizar
Created July 7, 2017 15:06
Show Gist options
  • Save Vadizar/b68effcee06d1b21404224eff618df1a to your computer and use it in GitHub Desktop.
Save Vadizar/b68effcee06d1b21404224eff618df1a to your computer and use it in GitHub Desktop.
Prevent links in standalone web apps opening Mobile Safari
<!DOCTYPE html>
<head>
<title>Stay Standalone</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<script src="stay_standalone.js" type="text/javascript"></script>
</head>
<body>
<ul>
<li><a href="http://google.com/">Remote Link (Google)</a></li>
<li><a href="javascript:alert('Awesome script is awesome')">JavaScript Link</a></li>
<li><a href="/">Local Link</a></li>
<li><a href="#amp">Local Anchor</a></li>
</ul>
</body>
// Mobile Safari in standalone mode
if(window.navigator.standalone){
var a=document.getElementsByTagName("a");
for(var i=0;i<a.length;i++) {
a[i].onclick=function() {
window.location=this.getAttribute("href");
return false
}
}
}
@Vadizar
Copy link
Author

Vadizar commented Jul 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment