JavaScript parse query string values

A quick post on how to use JavaScript to retrieve a query string value.

   // Function to parse the querystring
   getQueryString= function(sVar) {
        return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
    };

   // Get the value
   var queryParam = getQueryString("your key");

Leave a Reply

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