Reputation: 11
I am using a fancybox jquery plugin, what i need is to make sure before the website close a modal popup up and get us the details for submission to a form.
Please let us know how to make sure that before close a website a modal box fires up.
Have tried using unload method. It works when you use return but in return you can not use a form.
Please help!
Upvotes: 1
Views: 1271
Reputation: 382881
You can use onbeforeunload
event like this:
window.onbeforeunload = function(){
if (confirm('Are you sure you want to leave this page?')){
// user leaves
}
else{
// your code
}
};
Upvotes: 1