Sathishkumar Jayaraj Sathishkumar Jayaraj - 20 days ago 5
HTML Question

Modal popup on window close using javascript/jquery

I have a website where the customers come and purchase any product. But there are some customers who closes the tab without doing any purchase. I don't want to lose those customers. So

i have decided to provide offers for those customers in the "modal" popup. This popup has to be displayed once the customer clicks the close button in the browser
. This
popup will have a form
to select the offers, fill their contact details and submit the form. Once the form gets submitted, the window can be closed automatically. Is it possible to provide such a popup modal. I have surfed regarding this. Everyone says about the
onbeforeunload
with
confirm
and
alert
box. Could anyone help me on this.

Answer

What you are trying to do cannot be done. That is after the user has clicked on close there is no way to do it.
But I think what you are looking for is what is called a 'Exit intent popup'.
The idea is simple: you use js/jquery to find if the user is 'about to' close the page(say from mouse movements and such) and display the said popup.
Here is one such plugin : BIOEP

You can just google 'Exit intent popups' for many more.