When you close a browser window in Safari, and another tab contains text in a form that has not been submitted, you are prompted to see if you want to avoid closing the window (and losing what you were doing). There may be some other ways to add similar functionality for closing a tab while there is something to be submitted etc.
Example: