title: How to show confirmation of unsaved changes tags: web js From [this stackoverflow](https://stackoverflow.com/questions/10311341/confirmation-before-closing-of-tab-browser) ```js function onBeforeUnload(e) { if (thereAreUnsavedChanges()) { e.preventDefault(); e.returnValue = ''; return; } delete e['returnValue']; } window.addEventListener('beforeunload', onBeforeUnload); ```