-
-
Save carldanley/e3e1f609091f67356f59 to your computer and use it in GitHub Desktop.
Gets the parameters contained in a 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
function getURLParams( url ) { | |
var parts = url.split( '?' ); | |
if ( parts.length === 1 ) { | |
return {}; | |
} | |
var base = parts.shift(); | |
var params = parts.pop().split( '&' ); | |
if ( params.length === 1 && params[ 0 ] === '' ) { | |
return {}; | |
} | |
var result = {}, param; | |
for ( var i = 0, len = params.length; i < len; i++ ) { | |
param = params[ i ].split( '=' ); | |
result[ param[ 0 ] ] = decodeURIComponent( param[ 1 ] ); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment