I was wondering how to set an event listener for when the page closes
Does this help:
Yes. Thank you very much