Override default browser CTRL + F for a jQuery event

1

In the modification in question, the search field within the table is hidden, and I activate it with a 'enable search' button.

What I want to do is to enable this search with the keyboard, preferably CTRL + F, to do this is simple:

$(document).keydown(function (e) {
  if (e.keyCode == 70 && e.ctrlKey) {
     $("#dataTable_filter").find('.form-control').show().focus();
  }
});

But in this, it activates the default search of browsers, and moves the focus to that other search, the doubt is:

  

There is a way to disable this default search of browsers and use only the   my trigger? Or do you have to do otherwise to get this   result?

    
asked by anonymous 13.09.2017 / 15:59

1 answer

1

Test add e.preventDefault ();

$(document).keydown(function (e) {
  if (e.keyCode == 70 && e.ctrlKey) {
     $("#dataTable_filter").find('.form-control').show().focus();
     e.preventDefault();
  }
});

If it does not work try using it this way:

window.addEventListener("keydown",function (e) {
    if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) { 
        $("#dataTable_filter").find('.form-control').show().focus();
        e.preventDefault();
    }
})
    
13.09.2017 / 16:29