How to retrieve Query String Value using JQuery in SharePoint Online?

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:

In this tutorial, We discussed how to retrieve a Query String Value using JQuery in SharePoint Online Office 365.

  • 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?

  • >