Replace default browsers CTRL + F with a jQuery event

Where I have tables in my system, in almost all used the dataTables plugin to customize, but my plugin ta a little modified.

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

What I want to do activate this search with the keyboard, preferably CTRL + F, doing 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 browser search, and moves the focus to that other search, the doubt is:

Is there a way to disable this default browser search and use only the my trigger? Or do you have to do another way to achieve this result ?

Author: AnthraxisBR, 2017-09-13

1 answers

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 to use 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();
    }
})
 1
Author: Wictor Chaves, 2017-09-13 14:29:50