Is there any way to execute different functions in a beforeunload
event listener, based on whether the user chooses to leave the page or not?
window.addEventListener('beforeunload', (e) => {
// if (user chooses to leave)
func1(); // a value is sent to database
// else if (user chooses to stay on the page)
func2(); // actually nothing happens
});