Created
August 18, 2016 08:07
-
-
Save raphaelchaib/193bf0baa241387edbddf2e7b8a0f336 to your computer and use it in GitHub Desktop.
JavaScript: Get url parameters
This file contains hidden or 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
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