Skip to content

Instantly share code, notes, and snippets.

@Rayi
Forked from lbj96347/OpenANativeAppInWebApp.html
Created October 30, 2012 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rayi/3981068 to your computer and use it in GitHub Desktop.
Save Rayi/3981068 to your computer and use it in GitHub Desktop.
Open a native app in Web App
<!DOCTYPE html>
<html>
<head>
<!-- This is a template for Web App Setup -->
<!-- Author : @CashLee李秉骏 -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- Web App icon -->
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name='description' content='Open a native app in Web App 在Web中打开原生应用' >
<meta name='author' content='CashLee 李秉骏' >
<title>hello world</title>
<link rel='stylesheet' type='text/css' href='' />
</head>
<body>
<a id="open" href="YouAppName://">Open a native app 打开原生应用</a>
<!-- Your app should support scheme -->
<script type='text/javascript' language='javascript'>
var appstore = 'https://itunes.apple.com/us/app/[Your App Name]/id[Your App Id]?ls=1&mt=8';
var applink = function (app_link){
return function(){
var clickedAt = +new Date;
setTimeout(function(){
if (+new Date - clickedAt < 2000){
window.location = app_link;
}
}, 500);
};
}
/* Works in UIWebView | Mobile Safari | HomeScreen | */
document.getElementById("open").onclick = applink(appstore);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment