Warn User Before Leaving Web Page With Unsaved Changes JavaScript

Warn user before leaving web page with unsaved changes javascript is the todays tutorial. The onbeforeunload event handler is used to process beforeunload events. This event is fired when a window is about to unload its resources. This event would be used to check whether the user has left a form incomplete or unsaved data.

So i think it good to show warn like display warning before leaving the web page with unsaved changes using JavaScript. So i am here to share with you the following source code will help you make before leaving the web page with unsaved changes.

Example code:

window.addEventListener("beforeunload", function(e) {
  var confirmationMessage = 'It looks like you have been editing something. ' + 'If you leave before saving, your changes will be lost.';
   (e || window.event).returnValue = confirmationMessage;
});

 

Read also: How to Show and Hide Password When Click on Eye Icon Using jQuery

 

Hope it can help you.

 

#javascript