Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to hide the ribbon for all visitors.

I have seen solutions that require editing of master pages. This requirement is for one site only. I do not want to make this change for all the sites that use our master page.

Is there any way at all to accomplish this without editing the master pages, maybe with Javascript that can be embedded in a content editor web part?

Thanks, Ninel

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

Try using the SPSecurityTrimmedControl... Use CSS to hide the ribbon class, then use the SPSecurityTrimmedControl to show it when the user has the right permissions. This would be more lightweight than javascript. Also, this should be in the master page as Deepu mentioned.

more info on configuring the SPSecurityTrimmedControl: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx

share|improve this answer
    
I am trying to use the SPSecurityTrimmedControl. I'm having some issues. –  ninel Feb 21 '12 at 15:04
    
-I'm having some issues. I created an SP permission group "Site Visitor" with Read access. I placed the following code in my master page right above the <div id="s4-workspace">: 'code'<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ManageLists"> <script type="text/javascript"> document.getElementById("s4-ribbonrow").style.display = "block"; </script> </Sharepoint:SPSecurityTrimmedControl> [/code] It's not working. I log on as admin and the read only user and I still see the ribbon. What am I doing wrong? –  ninel Feb 21 '12 at 15:12
    
-I'm having some issues. I created an SP permission group "Site Visitor" with Read access. I placed the following code in my master page right above the <div id="s4-workspace">: 'code'<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="ManageLists"> <script type="text/javascript"> document.getElementById("s4-ribbonrow").style.display = "block"; </script> </Sharepoint:SPSecurityTrimmedControl> It's not working. I log on as admin and the read only user and I still see the ribbon. What am I doing wrong? –  ninel Feb 21 '12 at 15:16
    
Sorry for the double post...I also couldnt figure out how to post the code snippet properly. –  ninel Feb 21 '12 at 15:17
    
Did you hide the ribbon? Your code is showing it, but you should add, outside of the trimmed control some CSS which hides it. Add it above your control. –  David Lozzi Feb 21 '12 at 15:18
show 4 more comments

This requires you to modify your masterpage just a bit. It's minimal.

In your masterpage, find id="s4-ribbonrow" and add this to it:

style="display:none;"

Then add this after where that div ends

<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="FullMask">
<script type="text/javascript">
    document.getElementById("s4-ribbonrow").style.display = "block";
</script>
</Sharepoint:SPSecurityTrimmedControl>

Your result should be something like this:

<div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle" style="display:none;">
...
</div>
<Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="FullMask">
    <script type="text/javascript">
        document.getElementById("s4-ribbonrow").style.display = "block";
    </script>
    </Sharepoint:SPSecurityTrimmedControl>

This will only allow users with Full Control to see the Ribbon.
Read more about the Permissions to choose between here

share|improve this answer
    
If it's that minimal, then I will make changes to the master page copy. Thank you to everyone for such quick responses. –  ninel Feb 16 '12 at 16:45
add comment

Even though you embed JavaScript in a content editor web part for a page 'X', you will be able to hide the ribbon only for that particular page 'X' of the site. To implement the setting throughout any page in that particular subsite, you will need to do security trimming to your master page.

The best option would be to make a copy of your existing master page and add the security trimmed control to the ribbon. Then, make this master page as the custom master page for only that sub site.

In order to do that, you need to go to Site settings of that particular sub site -> Under Look and Feel -> Master pages -> Then select the option of specifying the new master page in the custom master page section. Everything should be fine then.

share|improve this answer
    
My site contains only one page so this solution with content editor web part would work for me. Any suggestions with CSS/Javascript? –  ninel Feb 16 '12 at 16:18
    
a site with only one page??? If that's the case then use the CSS in my answer below. That is a very unusual site though - is it likely to always be just one page? –  Dave Wise Feb 16 '12 at 16:26
    
I am not sure why you have a different site for just one page? Anyway, think about the future prospects too. If there will be more pages getting added up, it will be a overhead to make add the script in all pages. Otherwise, you can go with Dave's option, which would be the easiest. –  Deepu Nair Feb 16 '12 at 16:31
add comment

Hiding the ribbon via javascript and CSS is easy - however determining that the person is a Visitor instead of someone with higher permissions requires a security check on the server-side and that requires modifying the master page.

It is possible to do a pure javascript/css solution but doing this would introduce latency where visitors would first see the ribbon, then would see it disappear which is probably not desirable.

I would advise either making a copy of your master page for just this site and modifying that or leveraging a delegate control and then create a separate feature that can be activated per site that then injects the security check and ribbon logic into the delegate for just this site.

As far as actually hiding the ribbon goes, you only need the CSS below after all other CSS has loaded:

#s4-ribbonrow {
   display:none;
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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