Solution for JavaScript Error on Search Results Page in SharePoint

One of my clients reported that they have started getting “Object Expected” javascript error whenever they click on any link in Search Results of SharePoint. This was quite odd as the search results page was the out of the box search result page without any customization (…well up till now 😉 )…

After investigating the issue, I found out that client had deleted the “Search Box” web part from the search results page as they don’t want user to search again from the results page and you know what? “Object expected” error started popping up as soon as client removed the “Search Box” web part.

The reason is as follows:

  1. SharePoint records the user clicks on search results link.
  2. Recording of clicks utilizes a JavaScript function called “SendSoap” to asynchronously record the click.
  3. SendSoap function is defined in Search.js file located at /_layouts/ 1033 folder.
  4. Search Box web part includes this file on search results page.
  5. Search Core Results web part assumes that Search.js file will always be available and attaches the call to SendSoap on Search Result links.
  6. Deleting the Search Box web part will remove the reference to Search.js and as a result you will start getting the Object expected error whenever you click any link on results page.

Solution:

  1. If you really don’t want Search Box web part on your search result page then mark it hidden instead of deleting it. In this way, you will have the reference of Search.js in your search page.   OR
  2. Include the reference to Search.js manually either by CEWP or any other means, you feel appropriate.
Share