Reading SharePoint querystring values in JavaScript


JavaScript is becoming more and more popular as a language for SharePoint solutions. Time to get familiar with the built-in JavaScript repository. I have seen quite of different ways to retrieve querystring parameter values in JavaScript, but SharePoint features it’s own function ‘_spGetQueryParam(p)’.

The function ‘_spGetQueryParam(p)’ is loaded from the ‘init.js’:

function _spGetQueryParam(p)
	if(q && q.length > 2)
		var params=q.split("&");
		var l=params.length;
		for (var i=0;i<l;i++)
			var pair=params[i].split("=");
			if (pair[0].toLowerCase()==p)
				return pair[1];

You need to provide the lowercase name of the parameter to retrieve the value; e.g.:

var currentFolder = _spGetQueryParam('rootfolder')

About the author


You can leave a response, or trackback from your own site.

Leave a Reply