Lock F5 key in the application

2

Good afternoon, I'm developing a Java Web application, and I noticed that after making a registration and typing F5 the information is duplicated, only the ID that does not duplicate because it is serial. Can anyone help me if it is possible to block F5 . Thank you

    
asked by anonymous 30.06.2015 / 20:41

2 answers

0

Leticia , javascript version:

document.onkeydown = fkey;
document.onkeypress = fkey
document.onkeyup = fkey;

var foiPressionado = false;

function fkey(e){
        e = e || window.event;
       if( foiPressionado ) return; 

        if (e.keyCode == 116) {
             alert("F5 pressionado");
            foiPressionado = true;
        }else {
            alert("Proibido");
        }
 }

Demo

link

    
30.06.2015 / 21:38
0

One solution is to create a javascript function to prevent it from pressing the F5

function desabilitaF5(e) { 
  if ((e.which || e.keyCode) == 116) 
    e.preventDefault(); 
};

$(document).on("keydown", desabilitaF5); // com jQuery
//document.addEventListener("keydown", desabilitaF5); // com JavaScript

The problem with this is that he can still go with the mouse and click on the atualizar of the browser. To solve this you would have to create a mechanism to check if the user who sent the request is sending the same data as the last% of% you made and block.     

30.06.2015 / 20:47