-1

I want to make an alert when the user do Ctrl+F on the page. But I tried to do keydown just like below.

$(document).keydown(function(e){
    if (e.keyCode == 17 && e.keyCode == 70) {
        alert('Hello World!');
    }
});
Newbie
  • 85
  • 2
  • 12
  • 2
    Possible duplicate of [jquery: keypress, ctrl+c (or some combo like that)](https://stackoverflow.com/questions/4604057/jquery-keypress-ctrlc-or-some-combo-like-that) – JJJ May 10 '18 at 12:44
  • 1
    `e.keyCode` could not possibly have two values, could it ? – Gabriele Petrioli May 10 '18 at 12:57

3 Answers3

1

You can use ctrlKey function of javascript with key 'F'

$(document).keypress("f",function(event) {
  if(event.ctrlKey)
    alert("Find key.");
});
Devendra Soni
  • 391
  • 2
  • 11
0

try :

$(document).keydown(function(e) {
        if (e.keyCode == 70 && e.ctrlKey) {
            alert('ctrl F');
        }
    });
Chintan
  • 133
  • 8
0

just use .ctrlKey property of the event object that gets passed in. It indicates if Ctrl was pressed at the time of the event.

$(document).on("keypress","f",function(e) {
  if(e.ctrlKey)
    alert("Ctrl+F");
});
Bhavin Solanki
  • 4,740
  • 3
  • 26
  • 46