Friday, October 16, 2015

Extracts one named parameter from the QueryString (URL)

Use this below function to get values from Query string

URL: http://domainname.com/page.aspx?parameter1=xxx&parameter2=yyy

function getQueryStringParameter(paramToRetrieve) {
var params =
document.URL.split("?")[1].split("&");
var strParams = "";
for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] == paramToRetrieve)
        return singleParam[1];
}

var value=getQueryStringParameter('parameter1');

Even Microsoft duplicates functionality:

(SP.init.js) SP.ScriptHelpers.getUrlQueryPairs

Even more SharePoint code that does the same
 var QS = SP.ScriptHelpers.getUrlQueryPairs(document.location.href)
 var value=QS['parameter1'];

No comments:

Post a Comment