0

I have a document library where we only want people to see the default filtered view. To stop users from seeing all the files, I had hidden the Open In Windows Explorer button using the following code in a Content Editor Web Part:

<script type="text/javascript"> 

_spBodyOnLoadFunctionNames.push("hideToolbarItem()");    

function hideToolbarItem() {   
   var doc = document.getElementsByTagName('ie:menuitem');      
   for (var i = 0; i < doc.length; i++)   {     
       itm = doc[i];          
       if (itm.id.match('OpenInExplorer')!=null)  
       {             itm.hidden=true;          }
       if (itm.id.match('OfflineButton')!=null)        
       {             itm.hidden=true;          }   
   }  
}

</script> 

However, the button has recently re-appeared :-S I have admin powers to my sub-site, but not any higher powers so I don't know if anything higher up has changed.

Is there anything wrong with my code?

1

If you remove the "Browse Directories" permission level from the user, this button should be disabled by OOTB security trimming. Otherwise, you might want to consider using CSS or selecting on an ID "begins with" match in jQuery rather than using getElementsByTagName('ie:menuitem').

Try:

a[id^="Ribbon.Library.Actions.OpenWithExplorer"] { display: none; }

Or with jQuery:

$('a[id^="Ribbon.Library.Actions.OpenWithExplorer"]').hide();

The rendered markup of the button looks like:

<a id="Ribbon.Library.Actions.OpenWithExplorer-Medium"...>
    <span ...></span>
    <span ...></span>
</a>

But the size ("Medium") can change to "Small" if the browser viewport is shrunk down, so you can't rely on the ID itself. This is in IE 11, so just make sure you cross browser test as well.

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.