Skip to content

Instantly share code, notes, and snippets.

@m4dz
Created June 21, 2012 16:53
Show Gist options
  • Save m4dz/2966977 to your computer and use it in GitHub Desktop.
Save m4dz/2966977 to your computer and use it in GitHub Desktop.
Construct an object with the GET passing values
function getParams() {
var href,
paramList,
arg,
refs = {};
href = document.defaultView.location.href;
if ( -1 != href.indexOf("?") )
{
paramList = href.split("?")[1].split(/&|;/);
for ( p in paramList )
{
arg = paramList[ p ].split("=");
refs[ arg[0] ] = arg[1];
}
}
return refs;
}
@m4dz
Copy link
Author

m4dz commented Jun 21, 2012

protip : You can pass default values by filling the refs object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment