zoukankan      html  css  js  c++  java
  • 总结隐藏Ribbon菜单的方法

    1. 重载
    using (SPSite site = new SPSite("http://SP2010-01"))
    {
     using (SPWeb web = site.OpenWeb())
     {
      SPList list = web.Lists.TryGetList("Shared Documents");
      web.AllowUnsafeUpdates = true;
      SPUserCustomAction actionView = list.UserCustomActions.Add();
    
       StringBuilder newurl = new StringBuilder();
      newurl.AppendLine("<CommandUIExtension>");
      newurl.AppendLine("     <CommandUIDefinitions>");
      //Provide Location ID to hide the button
      newurl.AppendLine("        <CommandUIDefinition Location="Ribbon.Documents.New.NewFolder">");
      newurl.AppendLine("        </CommandUIDefinition>");
      newurl.AppendLine("    </CommandUIDefinitions>");
      newurl.AppendLine("</CommandUIExtension>");
    
       actionView.Location = "CommandUI.Ribbon";
      actionView.Title = "RemoveNewFolderButton";
      actionView.CommandUIExtension = newurl.ToString();
      actionView.Update();
    
       web.AllowUnsafeUpdates = true;
     }
    }
    2. 后台代码控制
    SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
    if (ribbon != null)
    {
    ribbon.TrimById(“RibbonGroupId”);
    }

    3. 使用javascript控制

    需要引用到

    • Core.js
    • CUI.js
    • Init.js
    • SP.Ribbon.js
    //使用RIBBON API
    <asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server">
     
       <!-- ScriptLink tags for sp.js and CUI.js could go here if you wish -->
     
       <script language="javascript" type="text/javascript">
     
          function DoSomethingWithRibbon() {
             // Gets a reference to a CUI.Ribbon object (CUI.js)
             var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
     
             // Show me which tab is selected - will show
             // 'Ribbon.Read' if the Browse tab is selected.
             alert(ribbon.get_selectedTabId());
          }
     
          // Note: 'SOD' is an abbreviation for "Script on Demand"
          SP.SOD.executeOrDelayUntilScriptLoaded(function() {
     
             var pm = SP.Ribbon.PageManager.get_instance();
     
             pm.add_ribbonInited(function() {
                DoSomethingWithRibbon();
             });
     
             var ribbon = null;
             try
             {
                ribbon = pm.get_ribbon();
             }
             catch (e) { }
     
             if (!ribbon) {
                if (typeof(_ribbonStartInit) == "function")
                   _ribbonStartInit(_ribbon.initialTabId, false, null);
             }
             else {
                DoSomethingWithRibbon();
             }
          },
          "sp.ribbon.js");
       </script>
    </asp:Content>

    实用隐藏方法

    function hideEditRibbon() {
               var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
               // Set the tab to the “Browse” tab
               SelectRibbonTab("Ribbon.Read", true);
               // Remove the “Edit” tab from a list from from the ribbon.
               ribbon.removeChild('Ribbon.ListForm.Edit');
         }
    
         SP.SOD.executeOrDelayUntilScriptLoaded(function() {
    
               var pm = SP.Ribbon.PageManager.get_instance();
         
               pm.add_ribbonInited(function() {
                    hideEditRibbon();
               });
    
               var ribbon = null;
               try {
                    ribbon = pm.get_ribbon();
               }
               catch (e) { }
    
               if (!ribbon) {
                    if (typeof(_ribbonStartInit) == "function")
                          _ribbonStartInit(_ribbon.initialTabId, false, null);
               }
               else {
                    hideEditRibbon();
               }
         },
         "sp.ribbon.js");
  • 相关阅读:
    能打开电脑都看懂的系列之Windows下修改MongoDB用户密码
    vue element el-input 输入框当内容长度超出时显示el-tooltip提示
    vue 数据代理帮助类 ux-data-proxy
    微信小程序全局设置分享内容
    解决vscode更新后Ext Js插件无法使用问题
    ux.form.field.Year 只能选年的时间扩展
    ux.form.field.Month 只能选年、月的时间扩展
    Ext Js 6+ 动态切换皮肤
    Ext Js 6.2.1 classic grid 滚动条bug解决方案
    Ext-JS-Modern-Demo 面向移动端示例
  • 原文地址:https://www.cnblogs.com/frankzye/p/3167779.html
Copyright © 2011-2022 走看看