Display a div when clicking on the close of the browser window [duplicate]

3

Does anyone know how I would display a <div> that is hidden when the user clicks the close button in the browser window?

    
asked by anonymous 13.01.2017 / 19:04

1 answer

1

In case you could run a javascript that displays an alert or a modal for it, eg:

<script>
window.onbeforeunload = function (event) {
  var message = 'Você tem certeza que deseja sair?';
  if (typeof event == 'undefined') {
    event = window.event;
  }
  if (event) {
    event.returnValue = message;
  }
  return message;
}

</script>

Documentation about the beforeunload event.

link

    
13.01.2017 / 19:21