I would like to make an alert, that when someine will refresh the page it will ask him or inform him something.
There are some examples, but in any case it works properly for me.
For instance, for code I've used here:
window.onbeforeunload = function() {
return "Data will be lost if you leave the page, are you sure?";
};
$(document).on("submit", "form", function(event){
window.onbeforeunload = null;
});
I have constant message, like below:
The same applies to the second code:
window.addEventListener('beforeunload', (event) => {
event.returnValue = `Are you sure you want to leave?`;
});
Is it something I am doing wrong here? I don't understand why the alert message is still thhe same.