Created
January 15, 2019 14:03
-
-
Save konratnox/87611672651a0a84a5514a9e87e0a4fc to your computer and use it in GitHub Desktop.
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
/** | |
* JavaScript Get URL Parameter | |
* | |
* @param String prop The specific URL parameter you want to retreive the value for | |
* @return String|Object If prop is provided a string value is returned, otherwise an object of all properties is returned | |
*/ | |
function getUrlParams( prop ) { | |
var params = {}; | |
if(window.location.search.length) { | |
var search = decodeURIComponent( window.location.href.slice( window.location.href.indexOf( '?' ) + 1 ) ); | |
var definitions = search.split( '&' ); | |
definitions.forEach( function( val, key ) { | |
var parts = val.split( '=', 2 ); | |
params[ parts[ 0 ] ] = parts[ 1 ]; | |
} ); | |
} | |
return ( prop && prop in params ) ? params[ prop ] : params; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment