Hello I need recommendation on the following scenario:

The basic idea is that I need to pop-up a survey form when a user abandons the shopping cart process. Abandonment includes the user closing the browser window while shopping, or going to another site (typing another URL in the browser address bar while shopping). So basically, I need to pop-up a survey form when the user decides not to complete the shopping up to the checkout.

Let me know if your have ideas on what JS functions/events can I use to achieve this. Thanks.