i want to detect browser close event and show alert message.
Situation when i want to show message is only exit/close browser tab not on refresh or click link.


  1. Google
  2. Leads to StackOverflow
  3. You've got your answer! Which is something like:


window.onbeforeunload = function (event) {
    var message = 'Important: Please click on \'Save\' button to leave this page.';
    if (typeof event == 'undefined') {
        event = window.event;
    if (event) {
        event.returnValue = message;
    return message;