Last active
June 10, 2018 11:21
-
-
Save pratk30/1ea7e9f2b58292bea24f3ff97fd471c1 to your computer and use it in GitHub Desktop.
Link Redirection using JQuery/CSS with Legacy URL (JSOM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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