5

I'm looking for a way to hide a button from the ribbon using javascript, but to do this I need to wait until the elements of the ribbon are loaded.

Is there a way to detect such event?

  • Any reason why you can not use a HideCustomAction: msdn.microsoft.com/en-us/library/ms414790.aspx – Robert Lindgren May 17 '13 at 9:10
  • Because I want to hide the Action under some conditions – must19 May 17 '13 at 9:12
  • Must19, i have similar issue of DOM being not available. How were you able to accomplish this? Thanks – user21997 Jan 15 '14 at 23:02
7

Here is some js that should load efter the ribbon is loaded:

SP.SOD.executeOrDelayUntilScriptLoaded(function() {
         // Your code here
      },
      "sp.ribbon.js");

More about modifying in this blogpost

Edit:

// Fires ‘ribbontabselected’ after the ribbon has been initialized after load
ExecuteOrDelayUntilScriptLoaded(function () {
var pm = SP.Ribbon.PageManager.get_instance();
pm.add_ribbonInited(function () {
 // Your code here
});
}, ‘sp.ribbon.js’);

from here

|improve this answer|||||
  • Thanx for the response. I tried this before, but do not garantee that the elements are attached to the dom. – must19 May 17 '13 at 9:24
  • Well I am not aware of any other events like "ribbon is loaded", so maybee you have to add a small delay in your code just to make sure all is loaded and well – Robert Lindgren May 17 '13 at 9:28
  • Updated with a more "complex" sample – Robert Lindgren May 17 '13 at 9:32
  • This worked fine. Thanx for helping – must19 May 17 '13 at 9:51

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.