Skip to content

Instantly share code, notes, and snippets.

@tomkuijsten
Last active October 18, 2016 19:06
Show Gist options
  • Save tomkuijsten/8d52953e216d4006a1328bfb56ffa415 to your computer and use it in GitHub Desktop.
Save tomkuijsten/8d52953e216d4006a1328bfb56ffa415 to your computer and use it in GitHub Desktop.
Html which redirects to another url based on query param
<html>
<head>
<script type="text/javascript">
// stolen from: http://stackoverflow.com/questions/11823784/redirection-to-a-specific-web-page-based-on-url-parameter-using-javascript
// http://minwinpc/RedirectUsingQueryParameter.html?selection=a
function getQueryStringArray(){
var assoc=[];
var items = window.location.search.substring(1).split('&');
for(var j = 0; j < items.length; j++) {
var a = items[j].split('='); assoc[a[0]] = a[1];
}
return assoc;
}
var qs = getQueryStringArray();
var url = '';
if (qs.selection !== 'undefined' && qs.selection) {
switch (qs.selection) {
case 'a':
url = '/imagebutton/a.html';
break;
case 'b':
url = '/imagebutton/b.html';
break;
}
window.location.href = url; //reroute
}
</script>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment