1window.addEventListener('beforeunload', (event) => {
2 event.returnValue = `Are you sure you want to leave?`;
3});
4
1let formChanged = false;
2myForm.addEventListener('change', () => formChanged = true);
3window.addEventListener('beforeunload', (event) => {
4 if (formChanged) {
5 event.returnValue = 'You have unfinished changes!';
6 }
7});
8