Last active
August 29, 2015 14:13
-
-
Save dirkteucher/fab3a24d30c6cc78d0bb to your computer and use it in GitHub Desktop.
// source http://jsbin.com/xehuse
This file contains 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
<!--Different ways to launch android apps or iOS apps--> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> | |
<meta charset="utf-8"> | |
<meta name="apple-itunes-app" content="app-id=333903271, affiliate-data=myAffiliateData, app-argument=myURL"> | |
<title>JS Bin</title> | |
<style id="jsbin-css"> | |
button { | |
padding: 10px; | |
margin: 5px | |
} | |
</style> | |
</head> | |
<body> | |
<h3>Ios</h3> | |
<p>Twitter meta tag for smart banner = Enabled | |
<a href="calshow://"> | |
<button>iOS open callendar -(Device) </button> | |
</a> | |
<br> | |
<a href="twitter://"> | |
<button>iOS Open Twitter -(Device) </button> | |
</a> | |
<br> | |
<a href="https://itunes.apple.com/us/app/pic-stitch/id454768104?mt=8&uo=4" target="itunes_store"> | |
<button>Pic Stitch -(store)</button> | |
</a> | |
<br> | |
<h3>Android</h3> | |
<a href="https://play.google.com/store/apps/details?id=cordproject.cord"><button>Cord - (store or browser) </button></a> | |
<br> | |
<br> | |
<a href="market://details?id=cordproject.cord"><button>Cord -(store)</button></a> | |
<br> | |
<br> | |
To open the application directly on apple/android an url scheme/intent filter needs to be added to the app and the name needs to be used in the href ie: <b>myAppName:// </b> | |
<br> | |
<br> | |
<script id="jsbin-javascript"> | |
var userAgent = navigator.userAgent; | |
var androidVersion; | |
function getAndroidVersion(ua) { | |
ua = (ua || navigator.userAgent).toLowerCase(); | |
var match = ua.match(/android\s([0-9\.]*)/); | |
androidVersion = match[1]; | |
return androidVersion; | |
} | |
getAndroidVersion(); | |
if(androidVersion>4.2){ | |
alert("launch app"); | |
ifrm = document.createElement("IFRAME"); | |
ifrm.style.width = 640+"px"; | |
ifrm.style.height = 480+"px"; | |
document.body.appendChild(ifrm); | |
//setting source does not working | |
//ifrm.setAttribute('src', 'twitter://');//only works on Safari | |
//Attaching a script to the iframe does not work either | |
//var scriptTag = "<script>//window.open(\"twitter:\/\/\", \"window name\")window.location.href = \"twitter://\"<"; | |
scriptTag += "/script>"; | |
//$("iframe").contents().find("body").append(scriptTag); | |
} | |
</script> | |
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html> | |
</html> |
This file contains 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
button { | |
padding: 10px; | |
margin: 5px | |
} |
This file contains 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
var userAgent = navigator.userAgent; | |
var androidVersion; | |
function getAndroidVersion(ua) { | |
ua = (ua || navigator.userAgent).toLowerCase(); | |
var match = ua.match(/android\s([0-9\.]*)/); | |
androidVersion = match[1]; | |
return androidVersion; | |
} | |
getAndroidVersion(); | |
if(androidVersion>4.2){ | |
alert("launch app"); | |
ifrm = document.createElement("IFRAME"); | |
ifrm.style.width = 640+"px"; | |
ifrm.style.height = 480+"px"; | |
document.body.appendChild(ifrm); | |
//setting source does not working | |
//ifrm.setAttribute('src', 'twitter://');//only works on Safari | |
//Attaching a script to the iframe does not work either | |
//var scriptTag = "<script>//window.open(\"twitter:\/\/\", \"window name\")window.location.href = \"twitter://\"<"; | |
scriptTag += "/script>"; | |
//$("iframe").contents().find("body").append(scriptTag); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Different ways to launch android, windows phone and iOS apps from a browser.
Reference "Android manifest file". The app name needs to be defined to use it.