When user click on an item display view (DispForm.aspx) the "View" ribbon is always expanded by default. It is annoying sometimes. How can I to make it collapse (not hide) by default? When user need the ribbon buttons he can click the "View" link at top to expand it.
2 Answers
By using the hints Anders provided and the reference here. I can make it work with below script. Simply put it into a Script Editor Webpart for the page you need it.
<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());
SelectRibbonTab("Ribbon.Read", true);
}
// 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>
You could do it with javascript I guess, the name of View
is Ribbon.Read
, so this should work:
SelectRibbonTab('Ribbon.Read', true);
-
By adding SP.SOD.executeOrDelayUntilScriptLoaded(myfunction, "sp.ribbon.js") The ribbon.read view is selected. However it is not collapsed.– Mark LMay 20, 2015 at 8:15
-
I got "Attempting to attach to Id: Ribbon.Read but this id is not present in the DOM" error in F12 tool.– Mark LMay 20, 2015 at 8:24
-