0

I have a pop up code written in my project. Simple I was using fading effect when mousemove. Bootstrap modal was showing perfectly on mousemove but I need to show modal when user closes the browser tab or leave the page. Below is my code

Before

$(document).on("mousemove", function (e) {
         $('#exitpopup').css('top', (window.innerHeight / 2 - $('#exitpopup').height() / 2));
         if (abc) {
             if (e.pageY >= 5) {
                 abc = false;
                 // Show the exit popup 
                 $('#exitpopup_bg').fadeIn();
                 $('#exitpopup').fadeIn();
                 abc = 0;
              }
         }
   });

Above code is working fine but how could I use fadeIn in below code or suggest me any other way please.

window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage; //Gecko + IE
  return confirmationMessage;                            //Webkit, Safari, Chrome
});
Vineet
  • 4,525
  • 3
  • 23
  • 42
  • Possible duplicate of [jQuery beforeunload custom pop up window for leaving a page](https://stackoverflow.com/questions/30712377/jquery-beforeunload-custom-pop-up-window-for-leaving-a-page) – reformed Sep 19 '17 at 19:38

1 Answers1

3

You can't. For security reasons, the only way to cancel the unload event in any browser is to ask. and of course, you cannot modify the dialog box that the browser will show. you can only give a string that will be displayed in the dialog. And since that functionality is for security, i don't think they will allow you to do that in any way.

litelite
  • 2,857
  • 4
  • 23
  • 33