The Ribbon shows certain tabs like 'Edit', 'View', 'Items', 'List' etc., when we are on a list form page or when a List is added to any SharePoint page. In some cases we do not want to show these tabs to the users, which can be hidden by adding JSOM code to remove the unwanted tabs. Below is the code to get an instance of the Ribbon and remove the Edit tab from the Ribbon. This JavaScript can be added to a certain list form page through a Script Editor WebPart or can be included in a custom list definition.
<script type="text/javascript"> function hideEditRibbon() { try { 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'); } catch (ex) {} } 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"); </script>
Below is the list of valid Ribbon tabs which can be hidden/removed by passing this value to the ribbon.removeChild method in the above snippet.
|
|