Skip to content

Instantly share code, notes, and snippets.

@oanhnn
Created December 1, 2015 04:05
Show Gist options
  • Save oanhnn/eff4468b320144c00abb to your computer and use it in GitHub Desktop.
Save oanhnn/eff4468b320144c00abb to your computer and use it in GitHub Desktop.
Launch app from web page snippets
<!DOCTYPE html>
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div style="width:0; height:0; overflow:hidden;">
<iframe id="launch_frame" name="launch_frame"></iframe>
</div>
<button id="app-launcher">Launch App</button>
<script type="text/javascript">
(function () {
function openApp() {
var appLink = 'myapp://invite?code=123';
var userAgent = navigator.userAgent.toLowerCase();
if (userAgent.search(/iphone|ipad|ipod|Android/) > -1) {
// Launch myapp via URL scheme
window.frames[0].location.href = appLink;
}
setTimeout(function () {
openDialog();
}, 500);
}
function openDialog() {
// TODO: open dialog here
console.log("App isn't installed");
}
window.onload = function () {
document.getElementById('#app-launcher').addEventListener('click', function(evt){
evt.preventDefault();
openApp();
}. false);
};
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment