Return to Snippet

Revision: 54753
at January 10, 2012 20:20 by ichnoweb

Initial Code
<!DOCTYPE html>
	<title>stay standalone</title>
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="viewport" content="width=device-width,initial-scale=1.5,user-scalable=no">
	<script type="text/javascript">
		(function(document,navigator,standalone) {
			// prevents links from apps from oppening in mobile safari
			// this javascript must be the first script in your <head>
			if ((standalone in navigator) && navigator[standalone]) {
				var curnode, location=document.location, stop=/^(a|html)$/i;
				document.addEventListener('click', function(e) {;
					while (!(stop).test(curnode.nodeName)) {
					// Condidions to do this only on links to your own app
					// if you want all links, use if('href' in curnode) instead.
					if('href' in curnode && ( curnode.href.indexOf('http') || ~curnode.href.indexOf( ) ) {
						location.href = curnode.href;
	<p><a href="">google</a></p>
	<script type="text/javascript" charset="utf-8">
		// NEVER user document.write, unless for test porposes.
		document.write('<p><a href="http://''/test/">Same domain</a></p>')
	<p><a href="/test/"><span>absolute path</span></a></p>
	<p><a href="test/">relative path</a></p>
	<p><a href="/test?">http not on beginning</a></p>
	<p><a href="#test">anchor</a></p>

Initial URL

Initial Description
Prevent links in standalone web apps opening Mobile Safari

Initial Title
Prevent links in standalone web apps opening Mobile Safari

Initial Tags

Initial Language