Showing posts with label QueryString. Show all posts
Showing posts with label QueryString. Show all posts

Monday, September 28, 2015

SharePoint Read values from query string parameter


You will always be wanted to read Query string parameter values using javascript in SharePoint 2013 due to the App models.
I was digging internal files of SharePoint 2013 for an issue and accidentally found out inbuilt javascript function "ReadQueryParam" to read query string parameter values.

You can make use of it. No need to write custom javascript/jQuery functions. If you are not able to call it then copy and paste the below SharePoint's javascript inbuilt function in your application (either in .js file or in your page).

function ReadQueryParam(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var results = (new RegExp("[\\?&]" + name + "=([^&#]*)")).exec(window.location.href);
    return (results == null) ? "" : results[1];
}






Friday, March 22, 2013

Getting Query String Values using JavaScript in SharePoint


The JSRequest class is a JavaScript object that lives on all SharePoint Pages, and allows us to simply and quickly get query string values 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 Id. i.e - "page.aspx?Id=11" will return 11
itemId = JSRequest.QueryString["Id"];

//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;



Ref: http://blogs.microsoft.co.il/blogs/itaysk/archive/2008/11/30/getting-query-string-parameters-with-javascript-in-sharepoint.aspx

https://www.nothingbutsharepoint.com/sites/devwiki/SP2007Dev/Pages/SharePoint%20JavaScript%20Functions%20Overview.aspx