I am working on a fairly simple evaluation system, but the point is that on the same screen a user can add dynamic elements and later fill in information.
The problem is that if a user (whether by mistake or for another reason) wants to refresh or close the tab, they are alerted about the pending changes or about the loss of their progress; Kind of like Facebook does when you leave a post halfway through and want to exit the tab.
What is the event that is triggered? or what function should be registered for it?
// Se ejecuta si el usuario trata de salir con cambios pendientes.
document.addEventListener('leave', fn (evt) {});
I imagine that in a way I also need to notify the browser that there are "things" pending, correct?
You can use the Window.onbeforeunload event to return a function, which in this case, prevents the user from quitting before saving the data.
if (typeof e == 'undefined')
This also works if you try to go back in the browser's History or try to refresh the browser window.
window.onbeforeunload
window.confirm()
I hope it will be of great help to you.