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
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:
- 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.
- Paste the below code with your own URLs.
<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.
I want to ask about the Group name, can I use both type of group name , sharepoint user group and active directory group !! ??
Very helpful , should you post the image in English please ?
Sure all next screen shoots will be in English MUI
Awesome
Thank you for the boatload of information!