Confirm Dialog when you are closing a browser window

1

Hello, my question is how can I make a dialogue message when a user wants to close the page to confirm if they want to leave or want to stay on the site, I tried in many ways that I saw by other posts and none It works for me, thank you very much

 xmlhttp.open("POST","LogoutAction",false); //esta es una de ellas.

and another would be through an onbeforeunload but it does not work either

 window.onbeforeunload = function (event) {
      var message = 'Sure you want to leave?';
      if (typeof event == 'undefined') {
        event = window.event;
      }
      if (event) {
        event.returnValue = message;
      }
      return message;
    };

    $(window).on('beforeunload', function() {
    var x =logout();
    return x;
    });
    function logout(){
            jQuery.ajax({
            });
            return 1+3;
    }

I'm trying this and it only works in firefox

    
asked by Rubén Dominguez Rivera 08.06.2018 в 13:17
source

1 answer

0

I recommend you onbeforeunload and try other browsers. I attached the code of it.

Code:

<script>
  $(window).on('beforeunload', function() {
    var x =logout();
    return x;
  });
  function logout(){
    jQuery.ajax({
    });
    return 1+3;
  }
</script>

At the time of leaving or giving a link that takes you to another page, it will show you this message.

    
answered by 08.06.2018 в 13:25