I have used this plugin - Local Storage & Cookies Plugin | Bubble to get this to work. You can store the previous URL that the user has visited and accordingly check when the user closes the popup