When developing SharePoint 2013, we often need to hide the ribbon, which is a feature of the office, but we do not want to see it when making a portal, but we can't do without it. When designing a list or document library as a management identity, we must use it. Without it, many functions cannot be implemented. Based on the preceding background requirements, we can use the spsecuritytrimmedcontrol control on the master page to identify the role of the current user on the website. It is easier to use it, we find the ribbon style class. In our style sheet, we hide it. When the Administrator is logged on, we will display the ribbon, as shown in the following code:
<!--MS:<SharePoint:SPSecurityTrimmedControl runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="AddAndCustomizePages">--> <script type="text/javascript"> document.getElementById("s4-ribbonrow").style.display = "block"; document.getElementById("suiteBar").style.display = "block"; </script> <!--ME:</SharePoint:SPSecurityTrimmedControl>-->
There are several ways to solve this problem.
Javascript Implementation Scheme:
function ShowRibbon() { $("#s4-ribbonrow").show(); $("#s4-workspace").height($(document).height() - $("#s4-ribbonrow").height() * 2);}function HideRibbon() { $("#s4-ribbonrow").hide(); var newHeight = $(document).height(); if ($.browser.msie) {newHeight = newHeight - 3; } $("#s4-workspace").height(newHeight);}_spBodyOnLoadFunctionNames.push("HideRibbon");
Encapsulate the JS file, use the vs development tool, package it into a solution package, and directly deploy it.