Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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