Pop Up Discount

Asked

Viewed 176 times

-2

Hello, I have a sales page and I am developing a pop up that offers a discount when the user moves his mouse to try to close the page! I don’t want the user to get stuck on my site, I just want you to open the pop up when it tries to close, offering a discount.

2 answers

2

This is immoral, and if you were my son and I caught you trying to do this kind of thing on a website you’d be out of my will.

Anyway... you mentioned in a comment in the other reply a certain site. What the site does is not open a popup, but a modal. This is different from opening a popup because it does not interfere with the behavior of the browser and does not open a new tab.

The site uses a library called Ouibounce, that you can find on Github. What the library code does is a function that checks the Y coordinate of the mouse cursor (which for Javascript is relative to the window). If the mouse is less than a number of pixels from the top of the window, it opens a modal.

Note that this means that the modal opens if you move the mouse to any higher point of the browser, like other tabs or even a menu. It will not necessarily fire only when someone moves the mouse to close or change tab, nor will it open the modal if the user uses keyboard shortcuts. It will also not work in mobile browsers or using different user experiences for obvious reasons.

If you have no soul or ethics you can modify the Ouibounce code to open a popup even instead of a modal.

  • I do not understand why it is immoral, I see only a page offering discount, nothing else, explains me the immoral part

  • @Fabio popups are unpleasant and can be vectors of attacks. Opening popups to make offers and advertisements is unethical. This is why today browsers block certain types of popup by default. This also causes, for example, the need for you to have to manually authorize popups on certain websites that have made bad design decisions. Note that the site you indicated in the other reply’s comment does not open popups. The library it uses opens modals, are something completely harmless (if not in aesthetics, at least in safety).

0

It is impossible to do anything when the user tries to close a tab or window, you can try to use the beforeunload event that works when the user clicks on a link, or tries to access another address in the same tab from the address bar. Or you can also try to add a Mousemove event and when the mouse has out Voce does what you want:

addEventListener("mousemove", function (e) {
    if (e.offsetY < 0) // acredito que nesse momento seja quando o mouse estiver perto do botao de fechar a pagina
});
  • Can I put a link here for example? for you to see what I want.

  • can yes, the will.

  • https://slimcaps.com.br/products take a look there, when I go to close the site, a pop up appears

  • 1

    @Fabio It seems to me that the site uses the event "mouseout".

  • truth and that’s right, ignore the Mousemove.

  • Personal thank you!

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.