Lock key f5 javascript

Posted on

Question :

Well, as the title itself indicates, I would like to know how to block the F5 key with Javascript.


Answer :

If your intention is to prevent the user from refresh in the browser, this will not be possible. It is the right of the user to do this.

If you want to use the F5 key for other functionality then the code for that key is 116 , you just need to have an event handset to the keydown event.

window.addEventListener('keydown', function (e) {
    var code = e.which || e.keyCode;
    if (code == 116) e.preventDefault();
    else return true;
    // fazer algo aqui para quando a tecla F5 for premida



Leave a Reply

Your email address will not be published. Required fields are marked *