SharePoint 2013: Get query string values using JavaScript or jQuery

This SharePoint jQuery tutorial explains, how to get query string values in SharePoint 2013 using JavaScript or jQuery. We can get the query string value inside the page by using JS request utility which we can put inside a SharePoint 2013 script editor inside the page.

The request is a utility which helps to get information from a URL. We can get information like File Name, Path Name & QueryString value from the URL.

var filename= JSRequest.FileName;
var pathname = JSRequest.PathName;
var parValue= JSRequest.QueryString["par1"];

To get the values like above first we need to initialize the request like below:

JSRequest.EnsureSetup();

Here is an example where we are trying to get the query string and other information by using JSRequest.

We put the below code in a script editor web part in NewForm.aspx (Edit the page and then click on Insert Web part and then from the Category select Script editor web part under media and content category).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<SCRIPT type=text/javascript>
jQuery(document).ready(function() {
JSRequest.EnsureSetup();
var itemId = JSRequest.QueryString["Itemuid"];
alert ('Item ID: '+itemId);
var fileName = JSRequest.FileName;
alert('File Name: '+fileName);
var pathName = JSRequest.PathName;
alert ('Path Name: '+pathName);
});
</SCRIPT>

The results will appear like below:

get query string value in jquery sharepoint
get query string value in jquery sharepoint

You may like following jQuery tutorials:

Hope this SharePoint tutorial explains, how to get query string values using JavaScript or jQuery in SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>