Hi,
Google can save lots of time for issues like you are facing. Solution to your problem is using confirm message box, you can implement like below
var result = confirm('Are you sure you want to leave the page?');
if (result == true)
else
For more details see
this[
^] reference.
You can also considered using
window.onbeforeunload
See
this[
^] example.
Hope this will help.