Tags

, ,

Init.js is included in JavaScript core files for SharePoint environment. From 2007 till 2013 it suffered some changes, new functionalities being added. What I am going to present was tested in SharePoint Online environment, but I have a feeling exists also in SharePoint 2013 on premise.

When you work with URL, you have all the functions you need included. No need to go to other libraries or creating your own code for this. For example, here is how you can decode full URL of a page.

var url = window.location.href;
CompleteDecode(url);

If you want to get the URL, but without a specified query string parameter, the function RemoveQueryParameterFromUrl is your friend;

RemoveQueryParameterFromUrl(url,'query string parameter name');

In an opposite way you can change a query string parameter:

StURLSetVar2(url,'query string parameter name','query string parameter value');

In case you have the specified query string parameter in the URL, it will take the specified value. If not, it will be added to the URL.
To get the URL, without query string parameters, you can simply remove them all using RemoveParametersFromUrl:

RemoveParametersFromUrl(url);

Even init.js is a SharePoint library, I think it can be used also for other technologies or at least it can be adapted. I really believe we can learn something from Microsoft analysing the provided code.

Advertisements