Просто измените url на http://localhost
вместо localhost
. Если вы откроете файл html из локального, вы должны создать локальный сервер для работы с этим html-файлом, самый простой способ - Web Server for Chrome
. Это устранит проблему.
Здесь вы идете.
<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(getUserGroup, "sp.js");
//found online
function getUserGroup() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);
var currUser = web.get_currentUser();
context.load(currUser);
var groups = web.get_siteGroups();
context.load(groups);
context.executeQueryAsync(
Function.createDelegate(this,
function () {
var isInGroup = false;
var groupEnumerator = groups.getEnumerator();
while (groupEnumerator.moveNext() && !isInGroup) { //go through all the groups
var oGroup = groupEnumerator.get_current(); //get current group in the enumerator
if (oGroup.get_title() == "SPM Team") { //is the group title named this?
var collUser = oGroup.get_users(); //get all the users in the group
context.load(collUser);
context.executeQueryAsync(
Function.createDelegate(this,
function () {
var userEnumerator = collUser.getEnumerator(); //get the enumeration
while (userEnumerator.moveNext() && !isInGroup) { //go through all users in group
oUser = userEnumerator.get_current(); //get current user in the enumerator
if (oUser.get_id() == currUser.get_id()) { //is the user's id the same as the viewer?
isInGroup = true;
console.log("success");
}
}
}),
Function.createDelegate(this,
function (sender, args) {
console.log(args);
}));
}
}
}),
Function.createDelegate(this,
function OnFailure() {
console.log("nope");
}));
}
</script>