Last active
January 22, 2019 12:07
-
-
Save marcusbelcher/234f74990f77d454b275d45f41f572fb to your computer and use it in GitHub Desktop.
Index page which prints GET Parameters from it's URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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