Hiding the Search Scopes Drop-Down in WSSv3/MOSS 2007

In WSS v3 and MOSS 2007, you may be inclined to hide the search scopes drop-down control from a specific page. This article will tell you how to do just that. While this may translate to 2010, I have not tried it as of this point.

What is this ‘Search Scopes’ control you speak of?
The Search Scopes drop-down control you will find to the left of the search box in SharePoint by default. If you are running WSS, or have this on a team site, you will generally see this populated, depending on your location, with the default for that page. Such as here, from the main page of this blank site template, it defaults to the “scope” of the site This Site: My Company (below).


If you drill down into a list, you will see this change, it is contextual in WSS, so it will by default, from a list page, default to the “scope” of just the list, as the example shows below, This List: My Generic List


But since that list is contained within the My Company site, you will see, you can drop the search box down to search not only the list, but also the site as well.


I don’t think I need to mention that depending on the scope you select, your search will execute against that search scope.

In MOSS 2007, or using Search Server Express on top of WSS, you will see your search scopes include whatever scopes have been defined at the Shared Service Provider level, in addition to the contextual WSS searches (This Site, This List), as shown below. The All Sites and  People searches are two default scopes in MOSS 2007 search.


Those scopes are configurable within the Shared Service Provider, and will only search on whatever content was configured for those scopes, so we will not get into all those possibilities, we’re just talking about hiding some part of the page here.

Ok, now that you’ve enlightened me on this “Search Scopes” control, how do I hide it?
Well, I am glad you asked, seeing as that is the point of the entire article! To hide it, we need to locate the control, and then toggle its visibility. First, lets view the page source, and see if we can find it. We know that the drop-down box contains the text This Site: My Company, so, lets search for that.


Now that we have located it, lets move back a bit from that control, and see if we can find the ID of the select box, or the ID of the cell in which it is contained, so we can hide it with just CSS.

NOTE: I know what some of you are thinking “Use Firebug!”, and “Use the IE Developer Toolbar!”. I know these are options people, but, I’m going for simple here. Lots of people have notepad, and lots of people know how to use that.

The following code contains the select control, as well as the surrounding table cell.

   1: <td class="ms-sbscopes ms-sbcell">
   2:     <select name="ctl00$PlaceHolderSearchArea$ctl01$SBScopesDDL" 
   3:         id="ctl00_PlaceHolderSearchArea_ctl01_SBScopesDDL" 
   4:         title="Search Scope" 
   5:         class="ms-sbscopes">
   6:             <option selected="selected" value="This List">This List: My Generic List</option>
   7:             <option value="This Site">This Site: My Company</option>
   8:     </select>
   9: </td>

If we look at this, the ID contains some dynamically generated stuff (ct100$blahblahblah$ct101), as does the name. Both are generated dynamically, so we should ignore those. We need something a bit more solid to land on, that is not going to change. That basically leaves us with the titles, as well as the classes of the search scopes drop-down box.

NOTE: Granted – when looking at a sampling of team sites on multiple local development images that I have, the control is the same within the code. However, I am going with something a bit more stable, the default styles that are attached to the TD surrounding the SELECT drop-down control.

I’m personally going to aim for the table cell (TD) which surrounds the select control, and hide that away. Your mileage may vary, you may want to go after the select control itself, and leave the table cell there.

So, with the table cell, we have no ID, we have no title, just the two classes, ms-sbscopes and ms-sbcell. How do we find the table cell with that? Magic? Voodoo? Increased taxes to the IRS? No, my dear friends, JavaScript. The frustrating client side scripting language of those who practice the martial art of SharePoint-fu.

Unfortunately I do not have the source readily available from where I found this code, it was quite a while ago when it found its way from the interwebs into my javascript toolkit, but, this is the code to get it done.

   1: <script type="text/javascript">
   2: document.getElementsByClassName = function(){
   3:     if(document.hasChildNodes && arguments[0]){
   4:         var data = new Array();
   5:         for(a=0;a<document.getElementsByTagName("*").length;a++){
   6:             if(document.getElementsByTagName("*")[a].className == arguments[0]){
   7:                 data.push(document.getElementsByTagName("*")[a]);
   8:             }
   9:         }
  10:         return data;
  11:     }
  12: }
  13: document.getElementsByClassName("ms-sbscopes ms-sbcell")[0].style.display = "none";
  14: </script>

What this does is locates the element, in this case, the TD, by it class names, and then allows us to work with it, in this case, setting the display style to “none”, hiding it, but not deleting it from the page (see below), so when a search is executed, the default selected search scope is used to fire off the search.

document.getElementsByClassName("ms-sbscopes ms-sbcell")[0].style.display = "none";

How do you use this? Well, you can drop it into a Content Editor Web Part, into the Master Page, etc. Once done, the search scopes drop-down should disappear from sight.



About Geoff Varosky
Geoff Varosky is a Senior Architect for Insight, based out of Watertown, MA. He has been architecting and developing web based applications his entire career, and has been working with SharePoint for the past 15 years. Geoff is an active member of the SharePoint community, Co-Founder and Co-Organizer of the Boston Area SharePoint Users Group, co-founder for the Boston Office 365 Users Group, co-organizer for SharePoint Saturday Boston and speaks regularly at SharePoint events and user groups.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: