Hide SharePoint Ribbon for anonymous user

SP2013


Hello everyone,

Today I will talk about a little trick for anonymous access on SharePoint 2013.

Often the customer tells you “I want a SharePoint but I do not want visitors to see the ribbon, there is no use for them!

Although I’m not entirely agree, sometimes I hide the ribbon for anonymous.

For this, a delegate control containing security trimmed control targeting anonymous 3 lines of JavaScript and is ready to deploy.

But then, if it looks good at first, there is a problem that appears when the anonymous visitor open a list item (eg an advertisement).

Indeed, by default when viewing an item, the ribbon load on the “View Item” tab which displays the ribbon large, which means that even hiding the ribbon via JavaScript, size dynamically taken the ribbon is reserved and we are stuck with a white stripe above our page!

To fix this little display problem, specify the ribbon to be minimized, which can be done in the following way.

« _ribbon.buildMinimized = true; »

The full code of the control is:


<SharePoint:SPSecurityTrimmedControl ID="HideSectionForAnonymous" 
runat="server" AuthenticationRestrictions="AnonymousUsersOnly">

<script type="text/javascript">

document.getElementById("globalNavBox").style.display = "none";

document.getElementById("suiteBar").style.display = "none";

 

function HideRibbon () {

if (_ribbon != null) {

_ribbon.buildMinimized = true;

}

}

_spBodyOnLoadFunctionNames.push("HideRibbon");

</script>

</SharePoint:SPSecurityTrimmedControl>

For information I add this user control via a delegate control as follows


<Control Id="PromotedActions" Sequence="1"
ControlSrc="~/_ControlTemplates/15/MyProject/HideTopRibbon.ascx" />

 

Hope this helps.

Christopher.

Advertisements
This entry was posted in SharePoint 2013 and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s