Wednesday, 3 July 2013

JSRequest to play with Query string

At times we are required to fetch some parameters from query string. There are various ways to play with it. Recently I came across a short and simple object to fetch parameters from query string.
JSRequest is a javascript object that lives on the SharePoint page through which you can easily find the query string parameter, filename and path name.


e.g. URL is /Pages/default.aspx?fName=Geetanjali&lName=Arora

JSRequest.EnsureSetup();            //mandatory
var fName = JSRequest.QueryString["fName"]; // returns Geetanjali
var lName = JSRequest.QueryString["lName"]; // returns Arora
var fileName = JSRequest.FileName;                // returns default.aspx
var pathName = JSRequest.PathName;             // returns /Pages/default.aspx

Quite simple as you can see from the above snippet. Hope it helps.

No comments:

Post a Comment