Pop Up discount [duplicate]

-2

Hello, I have a sales page and I'm developing a pop up that offers a discount when the user moves the mouse to try to close the page! I do not want the user to get stuck on my site, I just want him to pop up when he tries to close, offering a discount.

    
asked by anonymous 14.08.2017 / 15:29

2 answers

2

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

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

This site uses a library called Ouibounce , which 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 at the top of the window, it should open a modal.

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

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

    
14.08.2017 / 16:03
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 a link, or tries to access another address in the same tab by the address bar. Or you can try adding a mousemove event and when the mouse is outside you do 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
});
    
14.08.2017 / 15:41