Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 :-)

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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> 
share|improve this answer
    
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
add comment

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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