Dup Goto 📝

How to show confirmation of unsaved changes

PT2/lang/js/web web js 01-09 15:40:34
To Pop
14 lines, 22 words, 357 chars Tuesday 2024-01-09 15:40:34

From this stackoverflow

function onBeforeUnload(e) {
    if (thereAreUnsavedChanges()) {
        e.preventDefault();
        e.returnValue = '';
        return;
    }

    delete e['returnValue'];
}

window.addEventListener('beforeunload', onBeforeUnload);