Add a callback function for the close event.