Friday 30 August 2013

hide ribbon in sharepoint 2010

Ribbon is a great feature in SharePoint 2010, but some times it need to hide the ribbon from anonymous users. Here is a way by which you can hide the ribbon from anonymous users. This can be possible through Sharepoint:SPSecurityTrimmedControl control and some modifications in the master page and by using jQuery. If you want to read about Sharepoint:SPSecurityTrimmedControl, then visit this article. Also read some jQuery articles here.

Step-1:
First of all before modifying anything take a backup of your master page.

Step-2: 
Put the jquery-1.7.1.min.js file inside the layouts folder. Here I have created a folder name as Scripts and put my .js file inside the layouts directory.

Step-3:
Write below code in the master page, to refer to the .js file.
<SharePoint:ScriptLink language="javascript" name="/_layouts/Scripts/jquery-1.7.1.min.js" runat="server"/>

Step-4:
Now its time for modification in the master page.

Search for <div id="s4-ribbonrow" class="s4-pr s4-ribbonrowhidetitle"> and replace this with below line code (style="display:none")

<div id="s4-ribbonrow" style="display:none" class="s4-pr s4-ribbonrowhidetitle">

Step-5: Now search for this line <div id="s4-ribboncont"> , It usually appears after the above line.
After <div id="s4-ribboncont"> line write <Sharepoint:SPSecurityTrimmedControl runat="server" Permissions="ManageWeb">

Step-6:
Now search for the end ribbon tag that is  </SharePoint:SPRibbon>
And after this line write </SharePoint:SPSecurityTrimmedControl>

Step-7:
Now find this line <div id="notificationArea" class="s4-noti">
And above this line Write the below code:
 <SharePoint:SPSecurityTrimmedControl ID="st1" runat="server" PermissionsString="ManageWeb">
<script type="text/javascript">
$(document).ready(function()
{
$('#s4-ribbonrow').show();
});
</script>
</SharePoint:SPSecurityTrimmedControl>

Step-8:
This finishes our work. Now publish the page and enjoy.

No comments:

Post a Comment