2

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.

5

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

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 L May 20 '15 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 L May 20 '15 at 8:24
  • Ah, yeah. And i meant the "Browse" tab, not "View" btw :) – Anders Aune May 20 '15 at 9:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.