Manipulating URL with JavaScript in SharePoint Online

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;

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:


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.


One thought on “Manipulating URL with JavaScript in SharePoint Online

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s