Quick Tip: Change Search Result Page Client Side

One of the major limitation of the OOTB search navigation is that it is scoped to the web level. Not ideal for multiple subsites. Not practical for multiple site collections. So I was tasked with creating my own search navigation that was consistent across site collections.

All of the sites used the same master page so consistency wasn’t an issue. The challenge was changing the results page of the search box when the user clicks a different navigation element. Here’s how I did it.


<script>

EnsureScriptFunc('Search.ClientControls.js', 'Srch.U', function () {
   var boxId = $('#SearchBox').parent().attr('id');

   if (!boxId)
     return;

  var url = '/search/pages/myresults.aspx';
  var srchBox = $find(boxId);
  if (srchBox) {
    srchBox.set_resultsPageAddress(url);
  }

});

</script>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>