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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s