There comes a time where you will want to get a value out of the URL. Its a very easy process, just use the function below.

function getParameterByName( name ) {
name = name.replace( /[\[]/, "\\\[" ).replace( /[\]]/, "\\\]" );
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if ( results == null ) {
return "";
} else {
return decodeURIComponent( results[ 1 ].replace( /\+/g, " " ) );
}
};

The name value is the parameter from the URL that you want. For example in the following URL: http://www.awesomesite.com?userId=’1234′ if you wanted the value for userId you just pass ‘userId’ as the parameter to this method.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>