-3

I need js function that show alert window on reload or when closing tab asking me if I'm sure that want to reload or close tab. If not, Stay in page without loosing content.

user3749772
  • 21
  • 1
  • 2

1 Answers1

2

The browser feature that you want is called the onbeforeunload event.

window.onbeforeunload = function(e) {
  return 'Are you sure you want to leave? You are in the middle of something.';
};

When the data has been saved, you can clear the event like this:

window.onbeforeunload = null;
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74