# How to make a popup window when someone exits a website (not just a particular page)

**URL:** https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128
**Category:** Factual Questions
**Created:** [July 24, 2009, 3:02pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128 "2009-07-24T15:02:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![tim314](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tim314/32/3468_2.png) [@tim314](https://boards.straightdope.com/u/tim314)
#### Post date: [July 24, 2009, 3:02pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/1 "2009-07-24T15:02:55Z")

</div>

I’m trying to find a way to make it so that a popup will appear when the user exits a particular page of the site _unless they are going to another page within the same site_. (It’s that “unless…” that’s giving me problems.) Anyone know how to do this?

I realize exit popups are annoying and no one likes them. My boss wants me to do it so that’s what I’m doing.

---

<div class="post-metadata">

### Author: ![Markxxx](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@Markxxx](https://boards.straightdope.com/u/Markxxx)
#### Post date: [July 24, 2009, 3:08pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/2 "2009-07-24T15:08:39Z")

</div>

Try the website JavaScriptKit. Lots of free JavaScripts there. It’s fun to look around

---

<div class="post-metadata">

### Author: ![running\_coach](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/running_coach/32/15836_2.png) [@running\_coach](https://boards.straightdope.com/u/running_coach)
#### Post date: [July 24, 2009, 3:14pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/3 "2009-07-24T15:14:39Z")

</div>

> [@tim314](#):
>
> I’m trying to find a way to make it so that a popup will appear when the user exits a particular page of the site _unless they are going to another page within the same site_. (It’s that “unless…” that’s giving me problems.) Anyone know how to do this?
> 
> **I realize exit popups are annoying and no one likes them. My boss wants me to do it so that’s what I’m doing.**

I’m curious, what’s the content of the pop-up?  
I can tell you the I would never patronize a business that uses those things nor return to that website.  
Your boss needs to re-think this.

---

<div class="post-metadata">

### Author: ![Superfluous\_Parentheses](https://avatars.discourse-cdn.com/v4/letter/s/8edcca/32.png) [@Superfluous\_Parentheses](https://boards.straightdope.com/u/Superfluous_Parentheses)
#### Post date: [July 24, 2009, 3:25pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/4 "2009-07-24T15:25:59Z")

</div>

_unless_ the visitors are clicking links on your page to leave\*, you cannot do this. if they are clicking on links, you can just as easily catch that click instead of the onunload event. This also has the advantage that it will probably get past (some) pop-up blockers.

Now I feel dirty. Also: what **runner pat** said.

- ETA: the reason you can’t do that, is that for privacy & security reasons you will not (or at least, should not) get any information on the new location from the onunload event.

---

<div class="post-metadata">

### Author: ![tim314](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/tim314/32/3468_2.png) [@tim314](https://boards.straightdope.com/u/tim314)
#### Post date: [July 24, 2009, 3:27pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/5 "2009-07-24T15:27:52Z")

</div>

It’s basically for users who almost make a purchase and then navigate away at the last step, to ask them “Wait, don’t you want to finish purchasing our awesome product?” I guess the theory is that if they really had decided not to, then we’ve lost their business anyway and annoying them is unimportant.

Like I said, that part isn’t my decision.

---

<div class="post-metadata">

### Author: ![running\_coach](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/running_coach/32/15836_2.png) [@running\_coach](https://boards.straightdope.com/u/running_coach)
#### Post date: [July 24, 2009, 3:59pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/6 "2009-07-24T15:59:40Z")

</div>

> [@tim314](#):
>
> It’s basically for users who almost make a purchase and then navigate away at the last step, to ask them “Wait, don’t you want to finish purchasing our awesome product?” I guess the theory is that if they really had decided not to, then we’ve lost their business anyway and annoying them is unimportant.
> 
> Like I said, that part isn’t my decision.

It might be they go that far because the only way to find out the total cost(tax, shipping) of the product is to go through the checkout procedure and had not made the decision to buy yet.

I will always patronize and pay a bit more in exchange for being able to get the full cost without going through all that.

---

<div class="post-metadata">

### Author: ![YogSothoth](https://avatars.discourse-cdn.com/v4/letter/y/8edcca/32.png) [@YogSothoth](https://boards.straightdope.com/u/YogSothoth)
#### Post date: [July 24, 2009, 4:19pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/7 "2009-07-24T16:19:21Z")

</div>

Murder your boss

---

<div class="post-metadata">

### Author: ![HorseloverFat](https://avatars.discourse-cdn.com/v4/letter/h/8e8cbc/32.png) [@HorseloverFat](https://boards.straightdope.com/u/HorseloverFat)
#### Post date: [July 24, 2009, 4:22pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/8 "2009-07-24T16:22:09Z")

</div>

> [@](#):
>
> Wait, don’t you want to finish purchasing our awesome product?"

I hate that. I think you want to look at the window.onclose function in javascript. Some code here:

[http://javascript.internet.com/navigation/autoclose-inactive-popup.html](http://javascript.internet.com/navigation/autoclose-inactive-popup.html)

---

<div class="post-metadata">

### Author: ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)
#### Post date: [July 24, 2009, 4:23pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/9 "2009-07-24T16:23:53Z")

</div>

> [@](#):
>
> - ETA: the reason you can’t do that, is that for privacy & security reasons you will not (or at least, should not) get any information on the new location from the onunload event.

Obviously some other site won’t give you information on who they are, but couldn’t your own sites give you that information? Like, whenever any of your sites open, they send a signal to your browser that says “This is [Widgets.com](http://Widgets.com)”. Then, when the onunload event triggers, if you don’t get that signal within (say) a tenth of a second, or a half second, or whatever, it tosses up the popup. Would that be possible?

---

<div class="post-metadata">

### Author: ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)
#### Post date: [July 24, 2009, 4:59pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/10 "2009-07-24T16:59:28Z")

</div>

> [@Chronos](#):
>
> Obviously some other site won’t give you information on who they are, but couldn’t your own sites give you that information? Like, whenever any of your sites open, they send a signal to your browser that says “This is [Widgets.com](http://Widgets.com)”. Then, when the onunload event triggers, if you don’t get that signal within (say) a tenth of a second, or a half second, or whatever, it tosses up the popup. Would that be possible?

The problem is, you can’t really run scripts in a browser, just in particular documents - you’d probably need to have a hidden frame running things to manage such a scheme, but if you do that it’d be popular.

Actually, a hidden frame could do most of this by itself - if you set up all links out of your website such that they break the hidden frame and internal links to stay inside the hidden frame. If the user types in a new location or accesses a bookmark, that will unload the hidden frame. Hidden frame’s page\_unload has the popup trigger.

---

<div class="post-metadata">

### Author: ![Quartz](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/quartz/32/267_2.png) [@Quartz](https://boards.straightdope.com/u/Quartz)
#### Post date: [July 24, 2009, 8:10pm UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/11 "2009-07-24T20:10:57Z")

</div>

Please pass on this comment from a member of the public to your boss: “Please don’t do this; I hate pop-ups.”

Besides, it’s easily circumvented: I close the browser tab.

Actually, I suggest you say - or rather, put it in an email so you’re covered - to your boss something along the lines of, “Boss, I was researching the implementation of your requirement and the reaction was very hostile. Comments included … Do you still want me to go ahead?”

---

<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: [July 25, 2009, 12:54am UTC](https://boards.straightdope.com/t/how-to-make-a-popup-window-when-someone-exits-a-website-not-just-a-particular-page/504128/12 "2009-07-25T00:54:37Z")

</div>

> [@tim314](#):
>
> My boss wants me to do it so that’s what I’m doing.

The “I was just following orders” defense didn’t go over too well at the Nuremberg trials.

Just tell your boss it can’t be done.  
Doesn’t sound like he knows enough to distinguish between “it can’t be done because I am a moral person and won’t do evil things” and “it can’t be done because it’s not technically possible with our software”.
