Skip to content

Instantly share code, notes, and snippets.

@Gianfranco97
Created September 19, 2017 20:17
Show Gist options
  • Save Gianfranco97/7a3182f4ff7a22dcd8ae6abe20775f37 to your computer and use it in GitHub Desktop.
Save Gianfranco97/7a3182f4ff7a22dcd8ae6abe20775f37 to your computer and use it in GitHub Desktop.
Get data of the url
// 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