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

I need to hide the smallsearchbox until the page loads. Is there a way to inject a java script function into the process so that once the pages loads the box becomes visible?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

Actually, you neither need to go the long route of creating a replacement smallsearchbox DelegateControl, nor do you need to change the HTML body of your masterpage as mentioned in other answers.

All you need is the following CSS:

<style type="text/css">
#SRSB
{
    visibility: hidden;
}
</style>

which will hide the searchbox from the UI.

Now you need some JavaScript to make it visible again once the page finished loading. This could either be done with jQuery or with plain and simple script like this:

<script type="text/javascript">
if (typeof(_spBodyOnLoadFunctionNames) != "undefined")
{
  if (_spBodyOnLoadFunctionNames != null)
  {
    _spBodyOnLoadFunctionNames.push("ShowSearchbox");
  }
}

function ShowSearchbox()
{
  try
  {
    document.getElementById("SRSB").style.visibility = "visible";
  }
  catch (e) {}
}
</script>

The quick & dirty way to implement the above CSS & script code is to put it inside the <head> section of your masterpage by e.g. using SharePoint Designer (shudder).

The clean and reusable way is to develop a custom SharePoint DelegateControl as a feature and staple it on the placeholder "AdditionalPageHead", like described here:

https://littletalk.wordpress.com/2010/11/18/create-an-additionalpagehead-control-packed-into-a-feature-in-visual-studio-2010/

and here:

How can I enable JavaScript on every page at a site level?

The "AdditionalPageHead" approach has the added advantage that you can turn it off and on simply by flipping the feature on/off and it can be applied to any masterpage on any site.

share|improve this answer
    
This rocks dude. –  user2903 Feb 15 '12 at 21:35

If you want to do it for all the pages/sites then remove the Delegatecontrol from Master Page. If this does not work, you could remove it only visually by putting a div around it with display: none as CSS property. Something like this:

<div class="display:none">
  <SharePoint:DelegateControl runat="server" ControlId="SmallSearchInputBox" Version="4"/>
</div>

When SharePoint renders the page it definitely needs some contentplaceholders although you don't use it. The best way is to make them invisible.

share|improve this answer

Your Answer

 
discard

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