This SharePoint JQuery tutorial I will explain how to retrieve a Query String Value using JQuery in SharePoint Online Office 365. Here I have a SharePoint web part page which has a query string parameter, I want to retrieve the query string value using jQuery on the page load.
Retrieve Query String Value using JQuery
Here I was having a SharePoint web part page, where the query string parameter name is “MyID” and my web part page URL is like below:
https://onlysharepoint2013.sharepoint.com/sites/TSInfoIntranet/SitePages/MyDemoWebPartPage.aspx?MyID=5
Below is the jQuery code which we can use to retrieve the query string parameter value.
<script>
$(document).ready(function () {
var id = GetParameterValues('MyID');
if(id)
{
alert(id)
}
else
{
alert('No Query String Available')
}
});
function GetParameterValues(param) {
var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < url.length; i++) {
var urlparam = url[i].split('=');
if (urlparam[0] == param) {
return urlparam[1];
}
}
}
</script>
Here in this JQuery code, I have created a variable as “id” which is present inside the ready function[ready()]. In that “id” variable, I have passed the “MyID” get parameter values. The code is given below-
var id = GetParameterValues(‘MyID’);
Then after I created a function with function name and having parameter as-
[function GetParameterValues(param)]
In that function, I have used the “for loop” condition for retrieving the Query String Value.
You may like following jQuery SharePoint tutorials:
- How to uncheck add as a new version to existing files in SharePoint Online
- Cascading dropdown in SharePoint 2013/2016/Online using jQuery
- Jsom sharepoint 2013 examples: Retrieve List Items and display in Hyperlink using JavaScript Object Model in SharePoint Online
- How to bind current date to date picker using JQuery in SharePoint Online?
- Uncaught TypeError: Cannot read property ‘get_current’ of undefined error in jsom SharePoint Online
- Uncaught ReferenceError $ is not defined and Uncaught TypeError Cannot read property ‘SPGetCurrentUser’ of undefined
In this tutorial, We discussed how to retrieve a Query String Value using JQuery in SharePoint Online Office 365.
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 EnjoySharePoint.com
Superb blogs by you…keep growing like this….waiting for your blogs ….always…..love the way of explanation….keep it up…..
My parameter has %20 in it because of spaces, can you show how to remove the spaces? Also, instead of Alert output, how can I display on the page?