# Can a website detect a closing tab?

**URL:** <https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418>\
**Category:** Factual Questions\
**Created:** [January 8, 2019, 7:04pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418 "2019-01-08T19:04:55Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [January 8, 2019, 7:04pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/1 "2019-01-08T19:04:55Z")

</div>

Often I click on a video link to see something, and I’m met with an ad first. If I’m not that interested, I usually close the tab or browser. Can the hosting site detect that I’ve done so and possibly infer that the ad has annoyed me? If they can do it does anyone have any insight as to whether they actually check on such things?

---

<div class="post-metadata">

**Author:** ![ZipperJJ](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/zipperjj/32/211_2.png) [@ZipperJJ](https://boards.straightdope.com/u/ZipperJJ)\
**Post date:** [January 8, 2019, 7:47pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/2 "2019-01-08T19:47:38Z")

</div>

Yes. Web analytics will show how much time a user spent on your site and on each page. Some sites will try what is called A/B testing and show the ad to some people and not others and see how it affects people staying or leaving. Other sites will just look at the number of people who clicked on or followed through with the ad and decide if that number is worth continuing the ad, regardless of who may have been turned off by the ad.

---

<div class="post-metadata">

**Author:** ![Joey\_P](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@Joey\_P](https://boards.straightdope.com/u/Joey_P)\
**Post date:** [January 8, 2019, 8:02pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/3 "2019-01-08T20:02:37Z")

</div>

> [@OldGuy](#):
>
> Often I click on a video link to see something, and I’m met with an ad first. If I’m not that interested, I usually close the tab or browser. Can the hosting site detect that I’ve done so and possibly infer that the ad has annoyed me? If they can do it does anyone have any insight as to whether they actually check on such things?

If you click on a link and then leave it without doing anything else (or at least navigating to another page on the same site), that counts as a ‘bounce’. “Bounce rate”, the percentage of people that leave after visiting only the first page they landed on, is a very common item to track.  
It’s also trivial to track how long the person was on your site, where they came from and where they go after.  
Google Analytics makes this all very easy to track.  
TL;DR: Yes, they can tell if you go to their site and immediately leave.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [January 8, 2019, 8:15pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/4 "2019-01-08T20:15:26Z")

</div>

I’ve opened a webpage, decided I didn’t like how annoying it is and went to close the tab or close the window entirely. And as I’m moving the cursor to the upper right hand corner, something will pop up to say, “Wait! Before you go . . .” This is more than telling that I left the page quickly.

---

<div class="post-metadata">

**Author:** ![Tim\_T-Bonham.net](https://avatars.discourse-cdn.com/v4/letter/t/46a35a/32.png) [@Tim\_T-Bonham.net](https://boards.straightdope.com/u/Tim_T-Bonham.net)\
**Post date:** [January 8, 2019, 8:46pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/5 "2019-01-08T20:46:19Z")

</div>

> [@OldGuy](#):
>
> Often I click on a video link to see something, and I’m met with an ad first.

Ad-blocker, ad-blocker, ad-blocker! Don’t browse without one.

uBlock origin is the best one to use. It’s available (free) for Safari, Chrome, Firefox, Edge, etc.

Make sure you get uBlock Origin, not something from [uBlock.org](http://uBlock.org) – that is a fake site, owned by AdBlock. And watch out for ad-Block, too. That is a once-good ad blocker that has gone over to the dark side – they now let advertising companies pay to allow their ads through QAdBlocker.

---

<div class="post-metadata">

**Author:** ![glowacks](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/glowacks/32/5548_2.png) [@glowacks](https://boards.straightdope.com/u/glowacks)\
**Post date:** [January 9, 2019, 3:24am UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/6 "2019-01-09T03:24:07Z")

</div>

> [@Tim\_T-Bonham.net](#):
>
> Ad-blocker, ad-blocker, ad-blocker! Don’t browse without one.
> 
> uBlock origin is the best one to use. It’s available (free) for Safari, Chrome, Firefox, Edge, etc.
> 
> Make sure you get uBlock Origin, not something from [uBlock.org](http://uBlock.org) – that is a fake site, owned by AdBlock. And watch out for ad-Block, too. That is a once-good ad blocker that has gone over to the dark side – they now let advertising companies pay to allow their ads through QAdBlocker.

I’m not up to speed on everything that AdBlock does, but it does let through a few very harmless ads on very few websites that choose to serve the curated ads that AdBlock has deemed to be completely inoffensive. The main problem with modern ads for me is that they take up system resources without my permission. Banner ads require very little in computer resources.

---

<div class="post-metadata">

**Author:** ![Colophon](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@Colophon](https://boards.straightdope.com/u/Colophon)\
**Post date:** [January 9, 2019, 2:23pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/7 "2019-01-09T14:23:52Z")

</div>

> [@Joey\_P](#):
>
> If you click on a link and then leave it without doing anything else (or at least navigating to another page on the same site), that counts as a ‘bounce’. “Bounce rate”, the percentage of people that leave after visiting only the first page they landed on, is a very common item to track.  
> It’s also trivial to track how long the person was on your site, where they came from and where they go after.  
> Google Analytics makes this all very easy to track.  
> TL;DR: Yes, they can tell if you go to their site and immediately leave.

Can the tracking tell whether the tab is active? Eg if I open the window, then click another tab leaving the ad or whatever playing in the background - does that count as an active visiting session?

---

<div class="post-metadata">

**Author:** ![Inner\_Stickler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/inner_stickler/32/318_2.png) [@Inner\_Stickler](https://boards.straightdope.com/u/Inner_Stickler)\
**Post date:** [January 9, 2019, 2:33pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/8 "2019-01-09T14:33:51Z")

</div>

> [@Dewey\_Finn](#):
>
> I’ve opened a webpage, decided I didn’t like how annoying it is and went to close the tab or close the window entirely. And as I’m moving the cursor to the upper right hand corner, something will pop up to say, “Wait! Before you go . . .” This is more than telling that I left the page quickly.

That’s nothing. With [session replay scripts](https://www.welivesecurity.com/2018/04/20/whats-deal-session-replay-scripts/), websites can review everything you did on their website even if you never saved or submitted anything.

> [@Colophon](#):
>
> Can the tracking tell whether the tab is active? Eg if I open the window, then click another tab leaving the ad or whatever playing in the background - does that count as an active visiting session?

They definitely can tell if they want to how much time was spent focused or not.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [January 9, 2019, 2:41pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/9 "2019-01-09T14:41:36Z")

</div>

> [@Inner\_Stickler](#):
>
> > [@Dewey\_Finn](#):
> >
> > I’ve opened a webpage, decided I didn’t like how annoying it is and went to close the tab or close the window entirely. And as I’m moving the cursor to the upper right hand corner, something will pop up to say, “Wait! Before you go . . .” This is more than telling that I left the page quickly.
> 
> That’s nothing. With [session replay scripts](https://www.welivesecurity.com/2018/04/20/whats-deal-session-replay-scripts/), websites can review everything you did on their website even if you never saved or submitted anything.

I can see how they can track what links I clicked on in their site, or which pages I visited but don’t see how they can track my cursor movements if I’m not clicking on _anything_.

---

<div class="post-metadata">

**Author:** ![Inner\_Stickler](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/inner_stickler/32/318_2.png) [@Inner\_Stickler](https://boards.straightdope.com/u/Inner_Stickler)\
**Post date:** [January 9, 2019, 3:31pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/10 "2019-01-09T15:31:49Z")

</div>

> [@Dewey\_Finn](#):
>
> I can see how they can track what links I clicked on in their site, or which pages I visited but don’t see how they can track my cursor movements if I’m not clicking on _anything_.

Then [this website](https://clickclickclick.click) will freak you the fuck out. :eek:

Everything that website does is stuff that any webpage you visit can do. It just shows you.

---

<div class="post-metadata">

**Author:** ![Dewey\_Finn](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dewey_finn/32/4222_2.png) [@Dewey\_Finn](https://boards.straightdope.com/u/Dewey_Finn)\
**Post date:** [January 9, 2019, 3:36pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/11 "2019-01-09T15:36:03Z")

</div>

OK, so how does a website know where your cursor moved?

---

<div class="post-metadata">

**Author:** ![yabob](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/yabob/32/2821_2.png) [@yabob](https://boards.straightdope.com/u/yabob)\
**Post date:** [January 9, 2019, 4:29pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/12 "2019-01-09T16:29:32Z")

</div>

> [@Dewey\_Finn](#):
>
> OK, so how does a website know where your cursor moved?

I presume you mean the mouse pointer. One very simple way to respond to mouse position is onmouseover / onmouseout events. Useful, for instance, to display tooltips as the user rolls over something. The general answer is that javascript is running in your browser, and knows very well where the mouse pointer is.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [January 9, 2019, 5:18pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/13 "2019-01-09T17:18:36Z")

</div>

> [@Inner\_Stickler](#):
>
> Then [this website](https://clickclickclick.click) will freak you the fuck out. :eek:
> 
> Everything that website does is stuff that any webpage you visit can do. It just shows you.

More fun to [play with Neko the cat](http://webneko.net/)\*. Click on the cat in the upper left.

- Yes, “Neko the cat” is redundant. But not everyone knows …

---

<div class="post-metadata">

**Author:** ![rat\_avatar](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/rat_avatar/32/255_2.png) [@rat\_avatar](https://boards.straightdope.com/u/rat_avatar)\
**Post date:** [January 9, 2019, 6:02pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/14 "2019-01-09T18:02:12Z")

</div>

Note the “beforeunload” callback event can be used for this, although you would have to resort to blocking etc…to make sure it happens.

> **[Window: beforeunload event - Web APIs | MDN](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event)**
>
> The beforeunload event is fired when the current window, contained document, and associated resources are about to be unloaded. The document is still visible and the event is still cancelable at this point.

This is the source of this dialog:

> [@](#):
>
> Leave site:
> 
> Changes you made may not be saved.

That you will see when you, for example, type in a comment on Facebook but do not post it. If you open the inspector on this site you will see that chartbeat.js, yahoo-dom-event.js etc… are registered listeners for the unload event type as well as the vbulletin\_textedit.js so that the SDMB can know to discard your abandoned reply. There are some issues and limitations, but here is the documentation from one ad provider being used on this page when I made this post.

> **[User Engagement Tracking Methodology](https://help.chartbeat.com/hc/en-us/articles/360045890913-User-Engagement-Tracking-Methodology)**
>
> Engagement Tracking
> Engaged Time Window
> Chartbeat's JavaScript is constantly listening for acts of engagement on the in-focus webpage within an active browser (full list of events indicating engage...

> [@](#):
>
> Unload Pings  
> External: Chartbeat hooks into the beforeunload event for any users exiting the page (except via an internal anchor element click, which will be captured via the internal mechanism detailed below) to attempt one final ping. As this is an asynchronous event it is not guaranteed to succeed but Chartbeat has found that when combined with the internal unload pinging there is a 68% rate of success in capturing the final state of the pinger. Chartbeat does not attempt the ping in the unload event, as that would make exiting a page synchronous and in turn block the loading of the next page. This would contribute to users’ perception of slowness across Chartbeat’s client network and is an anti-pattern.
> 
> Internal: Chartbeat hooks into the unload event to store the current state of the pinger in the client for an hour after the user leaves a page. If the user returns to any page on that domain with Chartbeat’s pinger within the hour their final state will be sent.

---

<div class="post-metadata">

**Author:** ![Thin\_Ice](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@Thin\_Ice](https://boards.straightdope.com/u/Thin_Ice)\
**Post date:** [January 9, 2019, 6:23pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/15 "2019-01-09T18:23:49Z")

</div>

A porn site caught me masturbating once and told my mother. I’ll never go there again.

---

<div class="post-metadata">

**Author:** ![MDfive21](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@MDfive21](https://boards.straightdope.com/u/MDfive21)\
**Post date:** [January 9, 2019, 6:57pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/16 "2019-01-09T18:57:32Z")

</div>

if i input text into a text box like i’m doing to make this post, what happens to it if i close the tab before hitting submit? can the site see what i typed, as i typed it?

i’ve wondered this as i’ve interacted with online chat support people. can they see what i type before i hit enter?

---

<div class="post-metadata">

**Author:** ![Ashtura](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ashtura/32/2963_2.png) [@Ashtura](https://boards.straightdope.com/u/Ashtura)\
**Post date:** [January 9, 2019, 7:24pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/17 "2019-01-09T19:24:56Z")

</div>

It depends. I don’t think you can detect tab closes from a different domain in other tab unless there’s explicit coordination happening between the domains.

You definitely can detect when someone closes your own page though. There’s a built-in javascript event for that.

---

<div class="post-metadata">

**Author:** ![Ashtura](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ashtura/32/2963_2.png) [@Ashtura](https://boards.straightdope.com/u/Ashtura)\
**Post date:** [January 9, 2019, 7:31pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/18 "2019-01-09T19:31:01Z")

</div>

> [@MDfive21](#):
>
> if i input text into a text box like i’m doing to make this post, what happens to it if i close the tab before hitting submit? can the site see what i typed, as i typed it?
> 
> i’ve wondered this as i’ve interacted with online chat support people. can they see what i type before i hit enter?

Yes they could, but I doubt many do. You could have a key event send your keypress to their server on ever stroke. That’d have a lot of overhead though.

---

<div class="post-metadata">

**Author:** ![DesertDog](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/desertdog/32/11503_2.png) [@DesertDog](https://boards.straightdope.com/u/DesertDog)\
**Post date:** [January 10, 2019, 3:54pm UTC](https://boards.straightdope.com/t/can-a-website-detect-a-closing-tab/827418/19 "2019-01-10T15:54:47Z")

</div>

> [@Thin\_Ice](#):
>
> A porn site caught me masturbating once and told my mother. I’ll never go there again.

Gee, you’re lucky. I paid $150 to some guy in Hong Kong _twice_ because he said he had a recording of me masturbating that he would send to my mother, my co-workers, and my friends if I didn’t cough up. The third time I realized[ul]  
[li]My mother is dead[/li][li]I am retired[/li][li]My friends, being burners, don’t care[/li][li]I have no camera on this computer[/li][/ul]Boy, am I a sucker.
