Get Query String from SharePoint page
There were several JavaScript techniques to get query strings from URL, following are the few techniques are inbuilt in SharePoint. The main aim of this article is to use inbuilt SharePoint script techniques and to get rid of writing own JavaScript logic on every time.
1. GetUrlKeyValue
GetUrlKeyValue is an inbuilt JavaScript method exists in every page, you required to pass parameter to get the query string. You get query sting from a current url or from any url that passed as parameter to the method. It accepts a string as query string, bool for encoded value and a custom url.
var itemID = GetUrlKeyValue('ID');
var itemSourc = GetUrlKeyValue('Source');
var enSournce = GetUrlKeyValue('Source',true); // encoded result
var enSournce = GetUrlKeyValue('Source',false); // decoded result
var cId = GetUrlKeyValue('ID',false,'www.xyz.com?ID=2');
2. JSRequest
JSRequest is an inbuilt method used to query string from page, before query you need to ensure that JSRequest is loaded.
/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
var itemId = JSRequest.QueryString["ID"];
1. GetUrlKeyValue
GetUrlKeyValue is an inbuilt JavaScript method exists in every page, you required to pass parameter to get the query string. You get query sting from a current url or from any url that passed as parameter to the method. It accepts a string as query string, bool for encoded value and a custom url.
var itemID = GetUrlKeyValue('ID');
var itemSourc = GetUrlKeyValue('Source');
var enSournce = GetUrlKeyValue('Source',true); // encoded result
var enSournce = GetUrlKeyValue('Source',false); // decoded result
var cId = GetUrlKeyValue('ID',false,'www.xyz.com?ID=2');
2. JSRequest
JSRequest is an inbuilt method used to query string from page, before query you need to ensure that JSRequest is loaded.
/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
var itemId = JSRequest.QueryString["ID"];
Comments
Post a Comment