I'm building a chat page for a company and one of their requirements is a survey that pops up when the user closes the chat page. I tried using onunload but that launches the popup before the user connects to one of our customer service representatives. I believe this is because the chat form refreshes multiple times while connecting to customer service. My first idea was to see if the URL was still present, if so the popup wouldn't launch. However, this won't work as the URL will stay the same until the page closes. Once the page closes, the code will not be able to execute.My current idea is to implement a 1px by 1px iframe at the bottom of the document containing the script to launch the pop-up window when it's closed. I'm testing with an alert box and it works when the html file is opened directly in the browser, but not when it's closed while being in the iframe. What are some other options I could try?