Skip to content

Instantly share code, notes, and snippets.

@pratk30
Last active June 10, 2018 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratk30/1ea7e9f2b58292bea24f3ff97fd471c1 to your computer and use it in GitHub Desktop.
Save pratk30/1ea7e9f2b58292bea24f3ff97fd471c1 to your computer and use it in GitHub Desktop.
Link Redirection using JQuery/CSS with Legacy URL (JSOM)
<style>
.loadingBody {
display : none;
background: url("SharePointFolderURLFromSource/Redirecting.gif") 50% 50% no-repeat !important;
background-attachment: fixed;
background-position: center;
background-color: #cccccc;
}
</style>
<script>
var legacyUserGroupId = 329; //Your SharePoint Legacy group Id from Source Site
var getCurrentUser = function getCurrentUser() {
try {
var currentUserId = _spPageContextInfo.userId;
isUserMemberOfGroup(currentUserId, legacyUserGroupId,
function (isCurrentUserInGroup) {
if (!isCurrentUserInGroup){ //if ProjectTeamMember is present in legacy sharepoint group then redirection will not happen. End user will be redirected to new site.
setTimeout(function () {
$(location).attr('href', 'Target Site URL');
}, 3000);
$("#loading").addClass("loadingBody"); //adding loading class
}
},
function (sender, args) {
console.log(args.get_message());
});
}
catch (err) {
alert(err.message)
}
}
function isUserMemberOfGroup(userId, groupId, success, error) {
try {
var ctx = SP.ClientContext.get_current();
var allGroups = ctx.get_web().get_siteGroups();
var group = allGroups.getById(groupId);
ctx.load(group, 'Users');
ctx.executeQueryAsync(
function (sender, args) {
try {
var userInGroup = findUserById(group.get_users(), userId);
success(userInGroup);
}
catch (err) {
alert(err.message)
}
},
error);
var findUserById = function (users, id) {
var found = false;
var eUsers = users.getEnumerator();
while (eUsers.moveNext()) {
var user = eUsers.get_current();
if (user.get_id() == id) {
found = true;
break;
}
}
return found;
};
}
catch (err) {
alert(err.message)
}
}
$(document).ready(getCurrentUser);
</script>
<body id="loading"> //SharePoint Master Page Body tag with Id = loading
// Your Master Page content
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment