Redirect URL to different page in SharePoint before rendering using jQuery

Ahamed Fazil Buhari
Senior Developer
Published On :   30 May 2018
Visit Count
Today :  2    Total :   1238

Hello everyone,

In this article we will see how to redirect to different URL from SharePoint. Here we are going to redirect to different URL before anything renders on the page. In this scenario we need to redirect to different page if the user clicks or provide URL of specific SharePoint list, also we have added queryString functionality which helps admin to stay on the same page without navigation.

Consider we have list named Test in SharePoint - and if I provide this link in the browser then it should navigate to without rending anything from SharePoint. And if the URL is provided as then it will not redirect instead it will renders the actual page.

To achieve this, we updated the master page since we need to load this script before anything renders on the page. (Make sure to have backup of master page for safety J). My SharePoint site is using seattle master page.

Open the SharePoint Designer, go to Master Pages and right click on seattle.html and select ‘Edit File in Advanced Mode’


 <script src="">
 var relativeURL = document.location.href.split("?")[0];
 var targetURL = "";
 if (
   relativeURL &&"NewForm.aspx") === -1 &&"DispForm.aspx") === -1 &&"EditForm.aspx") === -1
 ) {
   var listName = relativeURL.toLowerCase().split("/lists/")[1];
   if (listName) {
     listName = listName.split("/")[0];
     if (listName === "Test") {
       var queryString = document.location.href.split("?")[1];
       if (queryString) {
         var params = queryString.split("&");
         var isRedirect = true;
         for (var i = 0; i < params.length; ++i) {
           var keyValue = params[i].split("=");
           if (keyValue[0] === "admin") {
             isRedirect = false;
         if (isRedirect) {
       } else {

Also we are not redirecting for NewForm, EditForm and DispForm. You can update the script as per your requirement.


Happy Coding