Monday, 12 October 2015

Get QueryString Parameters in JavaScript


Today I worked on a requirement where we need to read query string parameters on the load of the html page and do some operation based on the values.

Here is the JavaScript to read query string parameters.

function getQuerystringNameValue(name) {
    // page.htm?id=100&code=101&recid=102
    // Ex - passing a name parameter of "id" will return a value of "100", etc.
    var winURL = window.location.href;
    var queryStringArray = winURL.split("?");
    var queryStringParamArray = queryStringArray[1].split("&");
    var nameValue = null;
    for (var i = 0; i < queryStringParamArray.length; i++) {
        queryStringNameValueArray = queryStringParamArray[i].split("=");
        if (name == queryStringNameValueArray[0]) {
              nameValue = queryStringNameValueArray[1];
    return nameValue;

Hope this helps.

Happy CRM'ing

No comments:

Post a Comment