In a previous blog, we explored _spPageContextInfo variable properties. This time, we are exploring some SharePoint-provided useful methods and objects in JavaScript. Following are the methods and objects which we use frequently in JavaScript. All these are available Out-Of-The-Box and you don’t need to add any JavaScript library.
This is used for getting Query String Values. JSRequest class is a JavaScript object in SharePoint. Before using any of these properties, you should call JSRequest.EnsureSetup();
Ex: page URL is http://Siteur/ListName/EditForm.aspx?ID=9
To get a query string value, use the following code.
Similarly, you can use this -
GetUrlKeyValue(parameter, noDecode, url) (Method)
These SharePoint utilities and functions are available on the client-side of SharePoint 2013 to get the value from the query string of the URL.
The above statement will return the value ‘fi rst’. Here we are specifying our own URL.
The above statement will look for a query string variable ‘S’ in the browser URL and return the decoded value.
The above statement will look for a query string variable ‘S’ in the browser URL.
SetUrlKeyValue (parameterName, parameterValue, bEncode, url)This SharePoint utility is opposite to GetUrlKeyValue. In GetUrlKeyValue function, we will get the value from the query string and in SetUrlKeyValue, we will be setting the value to the query string .
Lots of this JavaScript Function is already written for you in SharePoint’s “Init.js“and “core.js” file follow the below tables,