question

developersp1-9584 avatar image
0 Votes"
developersp1-9584 asked Jerryzy answered

What does this code GetParameterValues function do?

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 ?

office-sharepoint-server-developmentoffice-js-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Jerryzy avatar image
1 Vote"
Jerryzy answered

Hi @developersp1-9584 ,

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.