What does this code GetParameterValues function do?

developer sp1 461 Reputation points
2021-02-10T05:48:42.557+00:00

I would like to know what this code does? I am using it almost all the time but I don't know what it does.

   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];
                }
            }
        }

And is there any other function which could get query string parameter directly ?

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
1,005 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,623 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerryzy 10,571 Reputation points
    2021-02-11T01:49:59.96+00:00

    Hi @developer sp1 ,

    It extracts one named parameter from the QueryString (URL), for example:

    http://domainname.com/page.aspx?parameter1=xxx&parameter2=yyy  
      
    var value=getQueryStringParameter('parameter1');  
    

    In SharePoint environment, you can use JsRequest.js to achieve the same function like this:

    JSRequest.EnsureSetup();  
    var value=JSRequest.QueryString['parameter1'];  
    

    Reference:

    Some Useful JavaScript Methods, Variable And Objects In Sharepoint 2013

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.