JavaScript to hide or select specific tabs in SharePoint Ribbon

I recently found a good post on how to hide specific tabs in the SharePoint Ribbon Menu

I used this on certain lists where I wanted the Browse tab to be the one that launches when opening up the Add Item form in a list. This works in SharePoint 2016 and SharePoint Online.
Reposting here in case the original post ever gets deleted.
Source: https://sharepoint247.wordpress.com/2013/05/24/javascript-to-hide-or-select-specific-tabs-in-sharepoint-ribbon/


Recently I spent few hours struggling to hide specific tab from the SharePoint ribbon. I did not find any working solution until finally I found a JavaScipt which could solve my problem.
This JavaScript can be used directly on your pages, web parts. Or simply put this script in content editor web part on the page.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script type="text/javascript">// <![CDATA[
function ResetRibbon() {
try {
var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
SelectRibbonTab("Ribbon.Read", true);
ribbon.removeChild('Ribbon.ListForm.Display');
ribbon.removeChild('Ribbon.ListForm.Edit');
} catch (e)
{ }
}
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
try
{
var pm = SP.Ribbon.PageManager.get_instance();
pm.add_ribbonInited(function () {
ResetRibbon();
});
var ribbon = null;
try {
ribbon = pm.get_ribbon();
}
catch (e) { }
if (!ribbon) {
if (typeof (_ribbonStartInit) == "function")
_ribbonStartInit(_ribbon.initialTabId, false, null);
}
else {
ResetRibbon();
}
},
"sp.ribbon.js");
}catch(e)
{}
// ]]></script>
<script type="text/javascript">
function ResetRibbon() {
try {
var ribbon = SP.Ribbon.PageManager.get_instance().get_ribbon();
SelectRibbonTab("Ribbon.Read", true);
ribbon.removeChild("Ribbon.ListForm.Display");
ribbon.removeChild("Ribbon.ListForm.Edit");
} catch (e)
{ }
}
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
try {
var pm = SP.Ribbon.PageManager.get_instance();
pm.add_ribbonInited(function () {
ResetRibbon();
});
var ribbon = null;
try {
ribbon = pm.get_ribbon();
}
catch (e) { }
if (!ribbon) {
if (typeof (_ribbonStartInit) == "function")
_ribbonStartInit(_ribbon.initialTabId, false, null);
}
else {
ResetRibbon();
}
} catch (e)
{ }
}, "sp.ribbon.js");
</script>
Thanks to this post (http://paulbuzzblog.wordpress.com/2012/11/23/how-to-hide-the-sharepoint-ribbon/) which helped me getting the final solution.


-------------------------------------------------------------------------------------
Another way would be to remove it using CSS

<style>
#suiteBar, #ms-designer-ribbon {
display: none;
}
</style>
--------------------------------------------------------------------------------------

Source: https://social.technet.microsoft.com/Forums/office/en-US/93780f44-80ff-46b5-a80f-bc4ef09e4113/how-to-remove-ribbon-and-sites-bar-on-a-particular-site-page-sharepoint-365?forum=sharepointgeneral

Share on Google Plus

About Tom DeMeulenaere

Highly accomplished information technology professional with extensive knowledge in System Center Configuration Manager, Windows Server, SharePoint, and Office 365.
    Blogger Comment

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.