How to close a window

Closing with javascript
Close the window
Show a message before closing the window
Show a message after closing the window
Ask before closing the window