咱們在開發Sharepoint 2013 的時候,經常須要隱藏Ribbon,那個Ribbon是屬於Office的特徵,可是咱們作門戶的時候,你們都不但願看見到它,可是咱們又離不開它,以管理的身份進行設計列表或文檔庫的時候,必須須要它,沒有它的話,不少功能就沒法實現了。基於以上背景需求,咱們能夠利用母版頁裏面的SPSecurityTrimmedControl控件,它的用途就是識別當前用戶在網站的角色,有了它就比較好辦了,咱們找到Ribbon 的樣式class,在本身的樣式表中,咱們隱藏掉它,當是管理員角色登陸的時候,咱們就顯示出Ribbon,以下代碼:javascript
<!--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>-->
如此簡單就解決了,其實還有好幾個辦法也能實現。java
Javascript的實現方案:ide
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");
封裝好JS文件,而後用VS開發工具,打包成解決方案包,直接部署就OK了。工具