Tuesday, February 25, 2014

How to get Query String parameters from JavaScript


We can easily set up a Javascript function that will retrieve the query string and load an array with the values passed in the query string. Here it is. This function goes into the head section of our page.

var qsParm;
        GetQueryStringParams();

        function GetQueryStringParams() {
            //Holds key:value pairs
            qsParm = new Array();
            //Get querystring from url
            var requestUrl = window.location.search.toString();
            if (requestUrl != '') {
                //window.location.search returns the part of the URL
                //that follows the ? symbol, including the ? symbol
                var query = requestUrl.substring(1);

                //Get key:value pairs from querystring
                var parms = query.split('&');

                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0) {
                        var key = parms[i].substring(0, pos);
                        var val = parms[i].substring(pos + 1);
                        qsParm[key] = val;
                    }
                }
            }
        }

1 comment:

prashanth said...

Great Information.it was very much useful.
Thanks for posting such a article.
keep sharing.

Split the String values with a special character in MS Flow to convert this into Array

 Many times we have a requirement to prepare the Mailing address for some of the documents, suppose there are Address Line1, Address Line2, ...