Javascript: Show alert before page reload or page refresh

By | March 4, 2018

The onbeforeunload event occurs when the document is about to be unloaded.

This event allows you to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page.

You can use this event as per your need using following approaches mentioned below:


In Javascript,

In JavaScript, using the addEventListener() method,

Thanks :)

Leave a Reply

Your email address will not be published. Required fields are marked *