2

We will show newsletter popup when customers leave the site Instead of showing popup on customers visit the site:

  • When customer is going to close the website?
  • When customer is going to go to another website?

How to do this. Thanks.

  • Can you please add the code which you have tried for your popup? – Jaimin Sutariya Jul 26 '17 at 9:23
3

This javascript 'onbeforeunload' event is used to detect browser close or changing website. You can use the event to display popup.

window.onbeforeunload = function () {
return "Do you really want to close?";
};
  • It doesn't work, indeed it displays the natif alert with the natif message but not with what your return, and is not what he is looking for ? HE WANT A NEWS LETTER POP UP ! – PЯINCƏ Jul 26 '17 at 8:42
  • 1
    I think this answer provides a starting point. The OP can use this and in place of return he can add his popup code. @Prince – Jaimin Sutariya Jul 26 '17 at 8:53
  • i want display popup newletter, not message – SonMai Jul 26 '17 at 9:07
  • 2
    The stay on the page message will appear but you can trigger to show the newsletter block in this function before return statement. And the user can decide to close the window or stay on page by seeing your newsletter window. – Athul Vijayan Jul 26 '17 at 9:15
  • 2
    window.onbeforeunload = function () { jQuery('#newsletter').toggle(); return true; }; – Athul Vijayan Jul 26 '17 at 9:17
0

You can do it in jquery. Please refer the Mouseleave and Mouseout function and set the event in your body tag. Popup block code shoud be in your header.phtml

For Example :

$( "body" ).mouseout(function() {
  //call your popup block
});

https://api.jquery.com/mouseleave/

https://api.jquery.com/mouseout/

Hope it will usefull for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.