# How do websites know you're about to close the tab, and pop up an advertisement?

**URL:** <https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646>\
**Category:** Factual Questions\
**Created:** [July 16, 2021, 3:56pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646 "2021-07-16T15:56:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ekedolphin](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ekedolphin/32/10003_2.png) [@ekedolphin](https://boards.straightdope.com/u/ekedolphin)\
**Post date:** [July 16, 2021, 3:56pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646/1 "2021-07-16T15:56:32Z")

</div>

Occasionally, when I move my mouse cursor up to where my tabs are, a website will pop up with something to try and entice me to stay-- an advertisement for other content they have on their site, or a sale offer, or something.

How does the website know where I’ve moved my mouse cursor to?

---

<div class="post-metadata">

**Author:** ![Telemark](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/telemark/32/372_2.png) [@Telemark](https://boards.straightdope.com/u/Telemark)\
**Post date:** [July 16, 2021, 4:08pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646/2 "2021-07-16T16:08:47Z")

</div>

Because cursor movements are events that can be tracked and trigger actions.

---

<div class="post-metadata">

**Author:** ![Acierocolotl](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/acierocolotl/32/6241_2.png) [@Acierocolotl](https://boards.straightdope.com/u/Acierocolotl)\
**Post date:** [July 16, 2021, 5:46pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646/3 "2021-07-16T17:46:05Z")

</div>

Telemark’s nailed it. It’s trivial to get your mouse coordinates.

Certain browsers (just tested on Firefox) accept CTRL-F4 to close the current tab.

---

<div class="post-metadata">

**Author:** ![TheGunIsMightierThanThePen](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/thegunismightierthanthepen/32/2981_2.png) [@TheGunIsMightierThanThePen](https://boards.straightdope.com/u/TheGunIsMightierThanThePen)\
**Post date:** [July 16, 2021, 6:05pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646/4 "2021-07-16T18:05:34Z")

</div>

Yep, try out [this site](http://www.brenz.net/snippets/xy.asp) that shows your mouse coordinates in real time.

> [@Acierocolotl](#):
>
> Certain browsers (just tested on Firefox) accept CTRL-F4 to close the current tab.

for Chrome users, it’s both CTRL + W and CTRL + F4

---

<div class="post-metadata">

**Author:** ![Keeve](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@Keeve](https://boards.straightdope.com/u/Keeve)\
**Post date:** [July 16, 2021, 6:06pm UTC](https://boards.straightdope.com/t/how-do-websites-know-youre-about-to-close-the-tab-and-pop-up-an-advertisement/946646/5 "2021-07-16T18:06:34Z")

</div>

I got pretty weirded out the first coupla times this happened to me. Out of nowhere, a big square in the middle of the screen pleading, “Please don’t leave!”.

And I wasn’t necessarily leaving, just going elsewhere to check something for a moment. Once I figured out what was going on, I moved the mouse very slowly to the edge, just from curiosity to see at which point it will consider me gone.
