Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react beforeunload

let formChanged = false;
myForm.addEventListener('change', () => formChanged = true);
window.addEventListener('beforeunload', (event) => {
  if (formChanged) {
    event.returnValue = 'You have unfinished changes!';
  }
});
Source by dev.to #
 
PREVIOUS NEXT
Tagged: #react #beforeunload
ADD COMMENT
Topic
Name
5+1 =