Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
558 B
1
Indexable
Never
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