Browsers have their own in-built alerts/confirmation boxes that they show when the user is about to close, go back or reload a page that contains a form (and has some data submitted into its fields; Chrome, as of version 60, waits until the user has interacted with the page in some manner or another, otherwise it suppresses alerts/confirmations).

However, I've added a small script that makes sure that the confirmation _does_ pop up when there's content on the data and the user tries to go back or reload the page (the messages it shows, though, are the browsers' default so they may be a bit verbose).

Here's a gif of me showing the errors on Chrome by 1) pressing the Back button and then 2) refreshing the page.

https://i.imgur.com/WmHrzN6.gifv