Using Ecma script we can find out user is logged in sharepoint site or not.
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "SP.js");
function getWebUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
context.load(this._currentUser);
context.load(web, 'EffectiveBasePermissions');
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
// Put your jquery logic for Successfully login
}
function onfaiuremethod(sender, args) {
alert('Anonymous User');
}
You can also get current user details using this code
ExecuteOrDelayUntilScriptLoaded(getWebUserData, "SP.js");
function getWebUserData() {
context = new SP.ClientContext.get_current();
web = context.get_web();
var userObject = web.get_currentUser();
alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());
}
No comments:
Post a Comment