Created
October 30, 2012 15:32
-
-
Save lbj96347/3980966 to your computer and use it in GitHub Desktop.
Open a native app in Web App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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