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:
You may like following jQuery tutorials:
- Show or Hide text box on dropdown selected index change event using HTML and JavaScipt
- Hide SharePoint list columns based on user permissions
- Create a Custom Calendar in SharePoint using Rest API and jQuery
- How to show/hide columns based on the value of SharePoint radio button
- Display SharePoint list data in jQuery data table using Rest API
- How to bind the dropdown list from an array using jQuery? And how to retrieve form control values using jQuery?
- jQuery Tooltip Using Visual Studio
Hope this SharePoint tutorial explains, how to get query string values using JavaScript or jQuery in SharePoint 2013/2016.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com