Getting Query String Parameters with JavaScript in SharePoint
Posted
Sunday, November 30, 2008 11:07 AM
by
Itay Shakury
The JSRequest class is a JavaScript object that lives on all SharePoint Pages, and allows us to simply and quickly get query string parameters using JavaScript.
It has 3 fields: QueryString, FileName, and PathName.
- QueryString - is an array of key\value pairs representing the current query string parameters.
- FileName - is a string containing the current name of the current page.
- PathName - is the server relative path of the current page.
Usage:
//First we must call the EnsureSetup method
JSRequest.EnsureSetup();
//Get a query string parameter called ItemId. i.e - "page.aspx?ItemId=11" will return 11
itemId = JSRequest.QueryString["ItemId"];
//Get the current page name. i.e - "default.aspx"
itemId = JSRequest.FileName;
//Get the current path name. i.e - "/itaysk/doclib/default.aspx"
itemId = JSRequest.PathName;
I have found no proper documentation for this so I hope it can help.
-- My name is Itay Shakury (itaysk) and I am a SharePoint consultant --