Show an alert before the refresh action?

2

What I'm looking for is the following: At the moment when the action is triggered to refresh the page, a message like this appears before me:

swal({
                    title: "Se perderan los datos",
                    text: "¿Desea refrescar la pagina?"
                    type: "warning",
                    showCancelButton: true,              
                    confirmButtonText: "refrescar",
                    cancelButtonText: "Cancelar",
                    closeOnConfirm: true,
                    closeOnCancel: true,

                }, function () {

                        //Cualquier cosa
                });

But I do not know the event and its use. Thanks in advance.

    
asked by Necroyeti 23.10.2017 в 17:08
source

1 answer

1

There is no event that is so specific (know that the action to be executed is "update"), but there is the event beforeunload (see documentation here) that allows asking the user's confirmation when leaving the page (either to reload it or to go to another address, that's something that we can not know for security reasons). Not all browsers behave exactly the same, but your function must return a string that will be displayed (or not, according to the policy of each browser) in a confirmation window to the user.

So you will not be able to use your own "confirmation window", neither a alert nor a confirm , it will be the browser that chooses what to show.

    
answered by 23.10.2017 в 17:40