Is there any way to show popup when close the browser tab? In popup there should be a button to see more and when user clicks that button user should be redirected to the see more page. If user click cancel button in the popup user will leave the website. Is there any possible way to do this? I currently try this code. It shows the popup but it suddenly dis-sappers. I think condition also not working.
var userclicked=false;
window.onbeforeunload = function(e) {
//e.preventDefault();
if(!document.hasfocus()){
Swal.fire({
title: 'New Promotions!',
text: 'Visit to See New Promotions!',
type: 'info',
showCancelButton: true,
confirmButtonText: 'View More',
cancelButtonText: 'Cancel',
showCloseButton: true
}).then((result) => {
if (result.value) { userclicked=true;
window.location = "{{url('front/promotionpage')}}";
} else if (result.dismiss === Swal.DismissReason.cancel) { userclicked=true;
}
});
if(userclicked){
return "Hi";
}else{
return null;
}
}
//return "hi";
//window.onbeforeunload = null;
//return null;
//return "Hi";
}