Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created March 25, 2014 12:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennadel/9760662 to your computer and use it in GitHub Desktop.
Save bennadel/9760662 to your computer and use it in GitHub Desktop.
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<!-- Stand-alone settings for iOS. -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- Load scripts. -->
<script type="text/javascript" src="./jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="./links.js"></script>
</head>
<body>
<h1>
Hello, Index Here
</h1>
<p>
Go to <a href="./index2.htm">Index 2</a>.
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Index 2</title>
<!-- Stand-alone settings for iOS. -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<!-- Load scripts. -->
<script type="text/javascript" src="./jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="./links.js"></script>
</head>
<body>
<h1>
Hello, Index 2 Here
</h1>
<p>
Go to <a href="./index.htm">Index</a>.
</p>
</body>
</html>
// Listen for ALL links at the top level of the document. For
// testing purposes, we're not going to worry about LOCAL vs.
// EXTERNAL links - we'll just demonstrate the feature.
$( document ).on(
"click",
"a",
function( event ){
// Stop the default behavior of the browser, which
// is to change the URL of the page.
event.preventDefault();
// Manually change the location of the page to stay in
// "Standalone" mode and change the URL at the same time.
location.href = $( event.target ).attr( "href" );
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment