I am using some JavaScript that can only be used in IE. Is there a way to hide my custom ribbon button if not in IE? Or only display it if it is IE.

1 Answer 1


The simpliest and recommended way: paste javascript: return navigator.appName == 'Microsoft Internet Explorer'; into your EnabledScript parameter of CommandUIHandler element. This will not hide the button, but disable it.

AFAIK, where is no legal way to hide a ribbon button based on client-side condition. Anyway, you can do this using DOM. You will need to hide an element with Id, equal to your button ribbon id + "-Large". For example, if your button has Id="Ribbon.Documents.New.MyCustomButton", you will need element with id "Ribbon.Documents.New.MyCustomButton-Large".

Final CommandUIHandler tag code will look like this:

    EnabledScript="javascript:if (navigator.appName != 'Microsoft Internet Explorer') document.getElementById('Ribbon.Documents.New.MyCustomButton-Large').style.display = 'none'; return true;" />

But even if it is possible, I don't really recommend you to use this code, because it is a kind of hack, and where are some scenarios, when this solution will not work.

For example, if you insert your button into standard ribbon button group, you will have to use standard control group template for it. And these templates are resizable: this means, that if you resize your browser window, their size could change accordingly. So, the "-Large"-postfixed elements will be hidden, and, for example, the "-Middle" ones will be shown. Ok, we can hide "-Middle" also, can't we? But if user will resize his browser window back, you "-Large" button will be shown out again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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