Lock key f5 javascript

3

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

    
asked by anonymous 18.06.2015 / 07:48

1 answer

8

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

jsFiddle

    
18.06.2015 / 09:05