Skip to content

Instantly share code, notes, and snippets.

@sergiks
Last active September 24, 2015 21:49
Show Gist options
  • Save sergiks/dce65d954778ffc12d15 to your computer and use it in GitHub Desktop.
Save sergiks/dce65d954778ffc12d15 to your computer and use it in GitHub Desktop.
GET parameters in JavaScript
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="robots" content="">
</head>
<body>
<script>
var params = window
.location
.search
.replace('?','')
.split('&')
.reduce(
function(p,e){
var a = e.split('=');
p[ decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
return p;
},
{}
);
body.innerHTML = "GET data:" + params['data'];
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment