Capture F5 and Execute Function

1

I'm doing a project with jQuery (Ajax y Json especificamente) , where the data I add to my document with JavaScript for which the pages do not have url, and if I do F5 all the data are erased, I try to capture the F5 and load them again the data, but only works when there is a Alert in between

var vta = 0;
function capturarf5(e) {
    //alert("f5");
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code === 116) {
        if (vta === 1)
            $("#contenedor").load("Lista");
    }
}
document.onkeydown = capturarf5;

Any way to reload the data?

    
asked by user75463 18.07.2018 в 00:28
source

1 answer

1

I recommend storing the data with Web Storage, that is, data that would be saved in the user's browser. Then you retrieve the data, if there are any.

The truth is that it's very simple, you just have to save your object as a JSON and with an alias, and when you want to recover it just call the storage with the alias and that's it.

To save:

sessionStorage.setItem('usuario',$('#txtUsuario').val());

To recover it

$('#txtUsuario').val() = sessionStorage.getItem('usuario');

Here you have more about this

link

    
answered by 18.07.2018 / 00:40
source