How to de-stress the keys except the F5? - JavaScript

0

I would like to know how to deactivate all the keys with the exception of the F5 since it serves to update.

This is the code, the bad thing is that all the keys are disabled including the F5.

 document.onkeydown = function(e) {
         if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) {


        }
        return false;
  };
    
asked by kyle 11.06.2017 в 23:47
source

1 answer

0

Make a conditional to deactivate the key only if the key code is different from 116 (F5).

const onKey = e => {
  if (e.keyCode !== 116) { e.preventDefault() }
}

document.onkeypress = onKey
document.onkeydown = onKey

It is important that you not only use keydown but also keypress .

    
answered by 12.06.2017 / 00:08
source