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

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.

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

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.

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.

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.

Murder your boss

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

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”. 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.

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?”

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”.