2

In my document library I have successfully hidden the Open In Explorer button by using the following code (code 1).

<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;          
          }   
    }  
  } 
</script>

I now need to hide the Connect To Outlook button

I tried to get the code to refer to both menu buttons but that didn't work (code 2)

<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)  
        if (itm.id.match('OfflineButton')!=null){
             itm.hidden=true;          
}   
}  
} 
</script> 

Also using the same code twice doesn't work (code 3)

<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;
            }
        }
    }
</script>
<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('OfflineButton') != null) {
                itm.hidden = true;
            }
        }
    }
</script> 

Both codes 2 and 3 result in Open In Explorer re-appearing and Connect To Outlook dissapearing. I need both gone!I don't know much about Javascript so an explanation of where I'm going wrong would be appreciated :-)

5

Try using below:

<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> 
  • Isn't that the same as my 2nd code? – Enilorac Nov 21 '12 at 13:46
  • No its not, you are writing same function twice! Try the given JS if it works or not :) – Arsalan Adam Khatri Nov 21 '12 at 13:52
  • Just tried it and it does work, thank you very much. I had to have both codes next to each other and stare at them before I could see the difference. At least I was close! – Enilorac Nov 21 '12 at 15:53
  • 1
    :) yeah you almost had it, I just restructured it ;) – Arsalan Adam Khatri Nov 21 '12 at 15:55
1

It is always a better approach to use the SharePoint Object Model for this type of thing, as opposed to hiding the physical HTML elements of the ribbon with JavaScript.

Here's a couple links to get you started (the second one specifically speaks to the "Open in Explorer" button):

http://www.learningsharepoint.com/2010/10/24/hide-ribbon-buttons-sharepoint-2010-programmatically/

http://sharepointegg.blogspot.com/2010/02/remove-button-from-ribbon-in-sharepoint.html

  • Thanks for the links, they both look pretty complicated and I forgot to mention I'm using 2007 – Enilorac Nov 21 '12 at 13:49

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.