Working in a view for a Document Library I enabled "inline-editing" and discovered that as any input-element receives focus the documents-ribbon-menu auto expands. This behavior is undesirable so my goal is to prevent the menu from auto expanding.

Through debugging I discovered suppressing window.SelectRibbonTab prevents this.

To resolve I created "test.aspx" so that when it is the current page the execution of window.SelectRibbonTab is suppressed, but all other page instances will remain unaffected. I attempted to pattern my override from these stack answers here & here but I'm unfamiliar with this concept and I am receiving a "Cannot assign to a function result" message.

Have a look at code below

window.SelectRibbonTab = function (obj) {
    if (location.pathname.search('test.aspx')=0) {
        return SelectRibbonTab.call(window, obj);


if (location.pathname.search('test.aspx') = 0) {

To this:

if (location.pathname.search('test.aspx') == 0) {

You are assigning zero to location.pathname.search('test.aspx'), not testing if it is zero.

Second part:

window.SelectRibbonTab = function (SelectRibbonTab) {
  return function ("Ribbon.Read", true) {
  if (location.pathname.search('test.aspx')==0) {
      return SelectRibbonTab.call(window, "Ribbon.Read", true);

I think this should work...I don't have a way to test it unfortunately.

FINAL Okay, so I finally figured it out :D

window.SelectRibbonTab = function (SelectRibbonTab) {
  return function (tabID, forced) {
  if (location.pathname.search('test.aspx')<0) {
      return SelectRibbonTab.call(window, tabID, forced);

Now, when you run the the function in the actual code (window.SelectRibbonTab("Ribbon.document")) I think it should run the custom function that you wrote (I hope).

| improve this answer | |
  • Thank you - that resolved the Cannot assign to a function message however now I am receiving a SCRIPT5002: Function expected message. – SP Combatant Jun 24 '14 at 13:02
  • Go into Firefox, and use the debugger to find the issue. It should tell you what is causing this error. Most likely, it is caused by a naming error, or type error. – Brandon C. Jun 24 '14 at 13:09
  • Actually, I know what is causing this. I will write into my original answer to answer the second part – Brandon C. Jun 24 '14 at 13:19
  • The idea behind this is that you are adding code onto the original function. So you are saying windows.SelectRibbonTab is now equal to the function that returns a constructor function, defining what action should be occuring. – Brandon C. Jun 24 '14 at 13:53
  • I ran Second part: but received Expected Identifier message. I see where you're headed though ...I think I'm making a mess of the Closure, the method signature is function SelectRibbonTab(tabId, force) When watched tabId="Ribbon.Document" and force is omitted I can even execute SelectRibbonTab('Ribbon.Document') in the console causing the ribbon to auto-expand. But I'm not clear on how the parameters and method signature are expressed in the Closure. Thank you for your continued help. – SP Combatant Jun 24 '14 at 14:39

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.