Skip to content

Instantly share code, notes, and snippets.

@noelrocha
Created March 16, 2015 18:28
Show Gist options
  • Save noelrocha/e423ff9ec98011e10ef7 to your computer and use it in GitHub Desktop.
Save noelrocha/e423ff9ec98011e10ef7 to your computer and use it in GitHub Desktop.
Open app on Google Play or AppStore
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Open App</title>
<!--
URL Params:
customSchemeURL: Your custom scheme app
storeURL: Your app url at App Store or Google Play
Any aditional parameter will be passed as param to the app url
-->
<script language="javascript">
var QueryString = function () {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = pair[1];
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]], pair[1] ];
query_string[pair[0]] = arr;
} else {
query_string[pair[0]].push(pair[1]);
}
}
return query_string;
} ();
function open_store() {
console.log("Timeout. Open fallback url: " + QueryString.storeURL) ;
document.location.href = QueryString.storeURL ;
}
var timeout;
function open_store_timeout() {
timeout = setTimeout('open_store()', 400);
}
function open_app() {
var customSchemeURL = QueryString.customSchemeURL ;
var customParams = "" ;
var separador = "" ;
for (var key in QueryString) {
if (["customSchemeURL", "storeURL"].indexOf(key) < 0) {
customParams += separador + key + "=" + QueryString[key] ;
separador = "&" ;
}
}
var appURL = QueryString.customSchemeURL + "?" + customParams ;
document.location.href = appURL ;
console.log("Opening URL: " + appURL) ;
open_store_timeout() ;
}
</script>
</head>
<body onLoad="open_app()" style="background: #00A4E6">
</body>
</html>
@apteachers
Copy link

What is customSchemeURL: Your custom scheme app
storeURL: Your app url at App Store or Google Play ?
Where do we change them.. Please specify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment