Untitled
unknown
plain_text
2 years ago
558 B
6
Indexable
let formChanged = false;
document.addEventListener('DOMContentLoaded', function () {
const form = document.querySelector('your-form-selector'); // Replace 'your-form-selector' with your actual form selector
if (form) {
form.addEventListener('change', function () {
formChanged = true;
});
window.addEventListener('beforeunload', function (event) {
if (formChanged) {
event.returnValue = 'You have unsaved changes. Are you sure you want to leave?';
}
});
}
});Editor is loading...
Leave a Comment