Lock Javascript F5 key

Asked

Viewed 1,887 times

3

Well, as the title indicates, I’d like to know how to lock the key F5 javascript.

1 answer

9


If your intention is to prevent the user from doing 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 key F5 for another feature then the code of that key is 116, You only need to have an event headphone keydown.

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
});

jsFiddle

  • 1

    It worked properly, thank you!

  • 2

    Keep in mind that this will only intercept the F5 key... Ctrl+R, Command+R and Menu>Refresh will still work...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.