JavaScript: getUrlParameter

Published on Author craigzearfossLeave a comment
/*
Returns the value of a url parameter.

reference: http://davidwalsh.name/essential-javascript-functions
*/

function getUrlParameter(sParam) {
    var sPageUrl = window.location.search.substring(1);
    var sUrlVariables = sPageUrl.split('&');
    for (var i = 0; i < sUrlVariables.length; i++)
    {
       var sParameterName = sUrlVariables[i].split('=');
       if (sParameterName[0] == sParam)
       {
           return sParameterName[1];
       }
    }
    return null;
}

Leave a Reply

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