Showing posts with label Query string. Show all posts
Showing posts with label Query string. Show all posts

Wednesday, December 5, 2012

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]);
}


Hope this helps...

Popular Posts