Monday, 2 January 2012

Get parameters from QueryString using JavaScript in SharePoint?

To get the querystring values, through JavaScript on a SharePoint site we can easily utilize the JSRequest object of MOSS.

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.

How to use it:

 <script language="javascript">

//First we have to call the EnsureSetup method
JSRequest.EnsureSetup();

//Get a query string parameter called ItemId. i.e. - "page.aspx?ItemId=5" will return 5
itemId = JSRequest.QueryString["ItemId"];

//Get the current page name. i.e. - "default.aspx"
itemId = JSRequest.FileName;

//Get the current path name. i.e. - "/abc/doclib/default.aspx"
itemId = JSRequest.PathName;

</script>

I hope this information will be helpful.



1 comment:

  1. The querystring property only works in Internet Explorer

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...