-4

I would like to print a message on the close of the browser tab. Something like this:

Please don't close this tab.....an important file is running on the same tab............closing this may lose the data

How do I do it?

David Rawson
  • 19,162
  • 6
  • 83
  • 120
saifio
  • 1

1 Answers1

2

You can use window.onbeforeunload

window.onbeforeunload = function(e){
    return "Do you want to close?";
}
philantrovert
  • 9,365
  • 3
  • 32
  • 56