SharePoint page redirect to another page based on the current user

In this post, we will learn how to perform a SharePoint page redirect to another page If the current user belongs to a specific group using JavaScript.

You might also like to read Show and Hide section based on SharePoint Group


SharePoint page redirect to another page

I have a web application ” http://epm/ “, and I need If the current user belongs to a specific SharePoint group go directly to “http://epm/pwa/” when he tries to browse the root URL “http://epm/”.

In such cases, you can easily perform SharePoint page redirect to another page using JQuery and SPServices by following the below steps:

SharePoint page redirect javascript

  • Download Jquery from here > Upload it to Style Library.
  • Download SPServices from here > Upload it to Style Library.
  • Open the web application home page ” http://epm/ “.
  • Edit page > Add web Part > below Media & Content  > Script Editor Web Part or Content Editor Web Part.
  • Edit Script.
Add Script Editor Web Part - SharePoint page redirect to another page
  • Paste the below code with your own URLs.

SharePoint page redirect script

<script src="/Style%20Library/js/jquery-1.7.1.min.js
"></script>
<script src="/Style%20Library/js/jquery.SPServices.min.js
"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
 $().SPServices({
 operation: "GetGroupCollectionFromUser",
 userLoginName: $().SPServices.SPGetCurrentUser(),
 async: false,
 completefunc: function(xData, Status) {
 if($(xData.responseXML).find("Group[Name='YourGroupName']").length == 1)
 {
window.location.href = "http://epm/pwa"; //redirect
 }
 }
 });
});

Applies To

  • SharePoint 2016.
  • SharePoint 2013.
  • SharePoint 2010.
See Also

5 thoughts on “SharePoint page redirect to another page based on the current user”

  1. I want to ask about the Group name, can I use both type of group name , sharepoint user group and active directory group !! ??

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top