Thursday, July 24, 2014

JavaScript to hide or select specific tabs in SharePoint Ribbon

<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>

No comments:

Post a Comment