Created
September 19, 2017 20:17
-
-
Save Gianfranco97/7a3182f4ff7a22dcd8ae6abe20775f37 to your computer and use it in GitHub Desktop.
Get data of the 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
// get data of the url | |
function getData (parm) { | |
var url = window.location.href | |
var queryStart = url.indexOf("?") + 1, | |
queryEnd = url.indexOf("#") + 1 || url.length + 1, | |
query = url.slice(queryStart, queryEnd - 1), | |
pairs = query.replace(/\+/g, " ").split("&"), | |
parms = {}, i, n, v, nv | |
if (query === url || query === "") return | |
for (i = 0; i < pairs.length; i++) { | |
nv = pairs[i].split("=", 2) | |
n = decodeURIComponent(nv[0]) | |
v = decodeURIComponent(nv[1]) | |
if (!parms.hasOwnProperty(n)) parms[n] = [] | |
parms[n].push(nv.length === 2 ? v : null) | |
} | |
return parms[parm] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment