disable or hide sharepoint buttons for extermal guests on a sharepoint comunication site. (modern sharepoint)

Christos Christopoulos 35 Reputation points
2023-06-20T08:48:39.4866667+00:00

Hello ,

It is very important for us to somehow eliminate or hide the buttons that appear in the following screenshots, especially the "Site Contents" and "Site Usage," as they contain content that we do not want to be visible to our external users.

Also we would like to the "Sent by email button" to disappear as well. Is there a way to do that please?

Below the screen shots.

Image

Image

Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Anonymous
    2023-06-21T06:44:55.1866667+00:00

    Hi @Christos Christopoulos,Do you want to eliminate the gear icon?

    Please try to use the SPFX extension:

    Before using the SPFX extension, we need to configure the environment:

    Please refer to the link below to create in order:

    References:
    Setup Environment: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment
    Build an extension: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/get-started/build-a-hello-world-exte...

    Then arrive at the sharepoint page, press F12, open the developer mode, we need to find the ID of the icon in the page:

    User's image

    Get the ID through JS code, and then remove

    Here is code:

    const canEdit = this.context.pageContext.web.permissions.hasAnyPermissions(SPPermission.manageWeb);
        if (canEdit) {
          let checkExist = setInterval(function () {
            const element = document.querySelector("#O365_MainLink_Settings_container").firstChild.firstChild.firstChild.firstChild;
            
              element.parentElement.parentElement.parentElement.remove();
              console.log("GFC user only has view rights.");
              clearInterval(checkExist);
            
          }, 100);
        }
    

    User's image

    Finally execute the SPfx extension

    Here is result:

    User's image

    If you want to control its existence based on permissions, please try the method under this link

    https://techcommunity.microsoft.com/t5/sharepoint/how-can-i-hide-the-gear-icon-based-off-permissions/m-p/1844401

    Hope these could help you!


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

  3. Christos Christopoulos 35 Reputation points
    2023-06-22T17:24:47.5766667+00:00

    Hello @Anonymous thanks for your help.
    It seems that is working.

    what about the send by email button?

    How can this be hidden or disabled?

    sharepoint2

    2 ) how the below bar can be hidden too from the document library page.
    sharepoint3

    thank you in advance.

    0 comments No comments

  4. Anonymous
    2023-06-23T08:29:54.82+00:00

    Hi Christos Christopoulos ,

    I'm sorry, there is no Sent by email button in my scenario, and I can't provide you with detailed test results.

    But the above method should also be able to hide it.

    This is not recommended for you to use this way, because it will destroy some functions of the original page, and may cause unexpected problems on the page.

    Here is a test for your reference:

    Then arrive at the sharepoint page, press F12, open the developer mode, we need to find the class of the web part in the pageUser's image

    Here is code:

    const canEdit = this.context.pageContext.web.permissions.hasAnyPermissions(SPPermission.manageWeb);
        if (!canEdit) {
          setInterval(() => {
            const element1 = document.querySelector("#O365_MainLink_Settings_container").firstChild.firstChild.firstChild.firstChild;
    
            element1.parentElement.parentElement.parentElement.remove();
            const element = document.querySelector(".od-ItemsScopeList-commandBar") as HTMLElement;
            if (element) {
              element.setAttribute("style", "display: none;"); // set  style  "display: none;"
            }
          }, 100);
        }
    

    User's image

    Here is result:

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.