I created a HTML page and uploaded it to a list and it’s working fine. My question is if I want a button to appear only to a specific organization or usernames only can that be done?


Im not really sure how you are using that HTML page, but here's what i did for SharePoint online. I wont share the entire code since it might be different for SP2013, but i hope you get the point.

You need to load all the needed js files from sharepoint, what i used was

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.js"></script>
<!--=================Sharepoint Related==============================================================================================-->
<script src="https://ajax.aspnetcdn.com/ajax/4.5.2/1/MicrosoftAjax.js"></script>
<script src="/_layouts/15/SP.js"></script>

After you load those you will need to get the user by doing something like this ->

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', getCurrentUser);

function getCurrentUser() {
    var splitUserName = _spPageContextInfo.userDisplayName.split(" ");
    firstNameUser = splitUserName[0];
    firstNameTrimmed = $.trim(firstNameUser);

I'm retrieving the user display name (first name) and appending it to a div on my page.

You can also check if the user is in any SP Group in SPO by using something like this ->

        var groupNames = ['GROUPNAME'];
        //determine wether current user is a memeber of group(s) 
        var userGroups = data.d.Groups.results;
        foundGroups = userGroups.filter(function(g){ return groupNames.indexOf(g.LoginName) > -1});
        if(foundGroups.length == 0) {
        } else {

What im doing is checking if the user is in that group and if not i'll simply hide some menu buttons from him.

  • I created a normal HTML file and uploaded it to pages library in sp 2013 online. Will I be able to use this file sp.js? I want to give certain users an admin view to edit some content but the content is only inside html not sp. Sorry, I'm new to sp. – Raghad Bogery Aug 6 '18 at 7:29
  • sp.js should be present in other version of SharePoint aswell (not only online). The approach above loads the users and you can then hide/show content on the page based on information that you receive from sharepoint. If you want onyl certain people to be able to EDIT the HTML page you should look into permissions for that file/library. Basically you'll need to create a sharepoint group which has full access and set the library to follow those permissions. For the rest of the users it will be "Read" permissions only. – Dante R. Aug 6 '18 at 11:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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