Search This Blog

Friday, November 27, 2015

Javascript to get query string value by passing the parameters siteUrl and querystringkey


In this post we will be writing a function to retrieve the query string value by passing the parameters siteUrl and querystringkey using Javascript.

Below is the function:
function getQuerystringForUrl(key,siteUrl) {   
    key = decodeURIComponent(key).replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + key + "=([^&#]*)";
    var regex = new RegExp(regexS);           
    var results = regex.exec(siteUrl);
    if (results == null)
        return;
    else
        return decodeURIComponent(results[1]);
}

No comments:

Post a Comment