Untitled

mail@pastecode.io avatar
unknown
plain_text
10 months ago
558 B
1
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?';
            }
        });
    }
});
Leave a Comment