How can I detect a page change or reload so that I can show a confirmation alert if I want to leave the current page or not.
var res = confirm('It\'s time to change. Do you agree with me?');
if (res) {
event.target.nextElementSibling.textContent = 'Yes, let\'s go for it.';
} else {
event.target.nextElementSibling.textContent = 'No, this is not the time.';
}