Skip to content

Instantly share code, notes, and snippets.

@artlung
Forked from anonymous/app-app-store-argument.js
Last active August 29, 2015 14:03
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 artlung/db7390a418aa0e718857 to your computer and use it in GitHub Desktop.
Save artlung/db7390a418aa0e718857 to your computer and use it in GitHub Desktop.
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var meta = document.getElementsByTagName('meta');
var apple_launch_elem;
for (var i=0;i < meta.length; i++) {
var elem = meta[i];
if (elem.getAttribute('name') === 'apple-itunes-app') {
apple_launch_elem = elem;
}
}
var launchurl = getParameterByName('launchurl');
if (apple_launch_elem) {
var tmp = apple_launch_elem.getAttribute('content');
apple_launch_elem.setAttribute('content', tmp + ', app-argument=' + decodeURIComponent(launchurl));
}
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var appleAppStoreID = "298307011";
var playLink = getParameterByName('launchurl');
document.writeln('<meta name="apple-itunes-app" content="app-id='+appleAppStoreID+', app-argument='+playLink+'" \/>');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment