Skip to content

Instantly share code, notes, and snippets.

@marcusbelcher
Last active January 22, 2019 12:07
Show Gist options
  • Save marcusbelcher/234f74990f77d454b275d45f41f572fb to your computer and use it in GitHub Desktop.
Save marcusbelcher/234f74990f77d454b275d45f41f572fb to your computer and use it in GitHub Desktop.
Index page which prints GET Parameters from it's URL
<!DOCTYPE html>
<html lang="en">
<head>
<title>Print GET Parameters from URL</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
/>
</head>
<body>
<div id="container"></div>
<script>
var container = document.getElementById("container");
var params = getParameters();
var keys = Object.keys(params);
addKeyValueToContainer("N# get parameters", keys.length);
for (var k of keys) {
addKeyValueToContainer(k, params[k]);
}
function getParameters() {
var getParamStr = window.location.search.substr(1);
return getParamStr != null && getParamStr != ""
? paramsToObj(getParamStr)
: {};
}
function paramsToObj(getParamStr) {
var params = {};
var arr = getParamStr.split("&");
for (var i = 0; i < arr.length; i++) {
var tmparr = arr[i].split("=");
params[tmparr[0]] = tmparr[1];
}
return params;
}
function addKeyValueToContainer(key, value) {
var t = document.createElement("div");
t.innerHTML = key + ": " + value;
container.appendChild(t);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment