I need to create notifications for every user who didn't read a specific new on the site. To do this i need to see who user is logged in the site and then save this info into a list on Sharepoint. The problem is that i don't know where can i get this info on Sharepoint Online. I whould like to do this using javascript.

Someone can help me whith this. Thanks

2 Answers 2


Best and simple way to get current logged in user name is _spPageContextInfo.


_spPageContextInfo is a global variable usually available on any SharePoint page. This variable stores basic information about current web and current user.

Below are the Some examples:

  1. To Get User Display Name:

    var currentUserName = _spPageContextInfo.userDisplayName;
  2. To Get User Login Name:

    var currentUserLoginName = _spPageContextInfo.userLoginName;
  3. To Get User Id:

    var userID = _spPageContextInfo.userId
  4. To Get User Email:

    var userEmail = _spPageContextInfo.userEmail

You can also use Rest API getting current user data:

 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser";  
        url: url,  
        headers: {  
            Accept: "application/json;odata=verbose"  
        async: false,  
        success: function (data) {  
            var items = data.d; // Data will have user object      
        eror: function (data) {  
            alert("An error occurred. Please try again.");  

This is the response data checked in Browser Console: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.