Skip to content

Instantly share code, notes, and snippets.

@carldanley carldanley/url-params.js Secret
Created Dec 4, 2013

Embed
What would you like to do?
Gets the parameters contained in a URL.
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
You can’t perform that action at this time.