I need to attached custom JavaScript function to SharePoint 2013 search button click. When user enter some text in search box and click search button or click "Enter" key, my custom JavaScript should also need to execute.

I can see the URL changes whenever user make a new query but it is not loading the entire page.

I added CEWP and added following code.

$(document).ready(function() {
    console.log("Log by search button click");

It is not writing the in to console log on search button click. It only writes when I reload the page manually..

Please suggest me how to make my custom function execute on every user search.

  • Out of curiosity, what are you doing on click? Mar 22, 2016 at 10:23

1 Answer 1


You will want to add an eventlistner.

If you have a pre-made function you want to call simply call it in the body of the eventlistener.

The below uses Jquery but normal JS works fine as well.

$(document).ready(function (){
    $("#ButtonID").on('click', function () {

function logIt()
   console.log("Log by search button click");
  • Thanks Roland.. I tried your code but it still not executing the function.. may be because of partial page load.. I am not sure.. Any suggestions
    – SPDev
    Mar 22, 2016 at 12:33
  • Are you getting any warnings/errors from the code? Also what search button are you referring to (the magnifying glass?)?
    – Roland
    Mar 22, 2016 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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