-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
  • 20,912
  • 7
  • 88
  • 124
saifio
  • 1

1 Answers1

2

You can use window.onbeforeunload

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