Skip to content

Instantly share code, notes, and snippets.

@raphaelchaib
Created August 18, 2016 08:07
Show Gist options
  • Save raphaelchaib/193bf0baa241387edbddf2e7b8a0f336 to your computer and use it in GitHub Desktop.
Save raphaelchaib/193bf0baa241387edbddf2e7b8a0f336 to your computer and use it in GitHub Desktop.
JavaScript: Get url parameters
var $_GET = {};
if(document.location.toString().indexOf('?') !== -1) {
var query = document.location
.toString()
// get the query string
.replace(/^.*?\?/, '')
// and remove any existing hash string (thanks, @vrijdenker)
.replace(/#.*$/, '')
.split('&');
for(var i=0, l=query.length; i<l; i++) {
var aux = decodeURIComponent(query[i]).split('=');
$_GET[aux[0]] = aux[1];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment