A handy trick I discovered for closing popups

F

fiziwig

I was looking for a way to have a popup window appear when someone left
my page, but not have it appear when they hit the refresh or back
buttons on the browser. Since using onUnload="..." in the body tag
causes the window to appear when you hit the refresh or back buttons,
that didn't do what I wanted.

After doing Google searches for many days I never did find an answer
for how to do this. I thought I could have each page open the popup
onUnload, but then also have each page close the window onLoad, so the
window only stays visible if you actually exit from my whole website.
The problem is, I didn't have the handle to the window object in the
page that wanted to close the window. I tried passing the handle in a
cookie, but that didn't work either.

My solution, which I haven't seen anywhere else before, works like
this:

Every page (they are php) includes the same header which has this code
in it:

var exit = true;
<?php
$popstuff = file_get_contents("_popstuff.txt");
$values = explode("|",$popstuff);
$usepop = $values[0];
if ($usepop!="on") {
echo("exit = false;\n"); // turn off popup window
}
?>
function offerWindow() {
if ( exit ) {
offerPop=window.open('_offer.php',
'offer','width=425,height=298,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0');
offerPop.blur();
window.focus();
}
}
function noExit() {
exit = false;
}
function closeOffer() {
offerPop=window.open('_offer.php',
'offer','width=0,height=0,resizable=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0');
offerPop.close();
}
// End -->
</script>
</head>
<body onUnload="offerWindow();" onLoad="closeOffer();">

Now what happens is if you leave the page it opens the popup, but
before you even get to see it, the next page closes it (by window name
instead of by handle). If you close the browser, or leave the whole web
page then the popup remains. If there is a path you wish to take out of
the site that does not show the popup then just include
onClick="noExit()" to the link and it turns off the popup. Normally the
links that go from page to page within the website will all include the
"noExit()" call so the popup never even shows up. But the problem where
the popup shows up on browser refresh or back buttons just goes away.

--gary
 
F

fiziwig

P.S. Ignore that little php snippet at the top of the example. That's
just for turning the popup off and on from a file of site options, and
has nothing to do with the Javascript example.

--gary
 
Z

Zilbandy

I was looking for a way to have a popup window appear when someone left
my page,

Remind me not to visit your page. Once someone leaves your page, you
should have nothing more to do with the visitor.
 
F

fiziwig

Zilbandy said:
Remind me not to visit your page. Once someone leaves your page, you
should have nothing more to do with the visitor.

--
Zilbandy - Tucson, Arizona USA <[email protected]>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I agree absolutely. Unfortunately, this was something a paying client
paid me to do. And no, I WON'T be visiting the page I made for him. And
NO, I would never do something like that on a page of my own.

--gary
 
Z

Zilbandy

I agree absolutely. Unfortunately, this was something a paying client
paid me to do. And no, I WON'T be visiting the page I made for him. And
NO, I would never do something like that on a page of my own.

Ah, a job! Well, you gotta eat, so I'll forgive you. :)
 
R

Randy Webb

fiziwig said the following on 11/21/2006 6:32 PM:
I agree absolutely.

Evidently you don't agree or you wouldn't be doing it.
Unfortunately, this was something a paying client paid me to do.

Ahh yes, the age old "The client made me do it" defense. If the client
wants you to do something stupid, then it is your job to convince the
client how stupid it is and how it will end up costing them money in
repeat business.
 
Z

Zilbandy

Ahh yes, the age old "The client made me do it" defense. If the client
wants you to do something stupid, then it is your job to convince the
client how stupid it is and how it will end up costing them money in
repeat business.

In a perfect world, maybe, but then again, in a perfect world you
wouldn't need to buy groceries, or pay bills. As long as it's not
illegal, I see nothing wrong with working for a living.
 
F

fiziwig

Randy said:
fiziwig said the following on 11/21/2006 6:32 PM:
Ahh yes, the age old "The client made me do it" defense. If the client
wants you to do something stupid, then it is your job to convince the
client how stupid it is and how it will end up costing them money in
repeat business.


Ah, what I wouldn't give to once again be under 30 and unrealistically
idealistic!

In point of fact, whether such a tactic annoys you or not, my client
has hard data to show that his "last chance offer" popup results in a
significant increase in his sales. I doubt he will abandon something
that works so well for him simply for abstract philosophical reasons.

--gary
 
L

Lee

fiziwig said:
Ah, what I wouldn't give to once again be under 30 and unrealistically
idealistic!

Lots of us have managed to hold onto our ethics well past 30.
In point of fact, whether such a tactic annoys you or not, my client
has hard data to show that his "last chance offer" popup results in a
significant increase in his sales. I doubt he will abandon something
that works so well for him simply for abstract philosophical reasons.

Really? How does he determine that? I would think that many customers
don't buy until at least their second visit to a site, and there's a
really good chance that fewer of these non-initial-visit-buyers return.
Even if a higher percentage of initial-visit-buyers accept his "last
chance offer", it could be driving his profits down.


--
 
R

Randy Webb

fiziwig said the following on 11/22/2006 11:12 AM:
Ah, what I wouldn't give to once again be under 30 and unrealistically
idealistic!

Me too and my children are approaching that age.
In point of fact, whether such a tactic annoys you or not, my client
has hard data to show that his "last chance offer" popup results in a
significant increase in his sales. I doubt he will abandon something
that works so well for him simply for abstract philosophical reasons.

<sarcasm>Did he get those stats from a popup survey?</sarcasm>
 
F

fiziwig

Randy said:
fiziwig said the following on 11/22/2006 11:12 AM:


<sarcasm>Did he get those stats from a popup survey?</sarcasm>

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

There are certain free products he only offers via the popups. If those
products land in the basket at checkout time then the customer came
back into the store via the popup.

Anyway, I'm just a coder, and I do what the boss tells me to do, and he
does what the client tells him to do, and the customer is always right.
At least until he discovers for himself that he's wrong.

--gary
 
L

Lee

fiziwig said:
There are certain free products he only offers via the popups. If those
products land in the basket at checkout time then the customer came
back into the store via the popup.

Ok, but what does that tell you about the people who left in disgust,
never to return? How much more profit might he make if he offered
those free products to everyone, not just the ones who wanted to shop
around a little more before buying? He doesn't know, and believes what
he chooses to believe.
Anyway, I'm just a coder, and I do what the boss tells me to do, and he
does what the client tells him to do, and the customer is always right.
At least until he discovers for himself that he's wrong.

If you're desperate or have no ethics, then the customer is always right.
If your boss tells you to do whatever the client wants, start looking for
a boss who has ethics. If you work for a jerk, you're going to get
screwed sooner or later.


--
 
R

Randy Webb

fiziwig said the following on 11/22/2006 6:59 PM:
There are certain free products he only offers via the popups. If those
products land in the basket at checkout time then the customer came
back into the store via the popup.

Go outside your bosses brick and mortar store and every time someone
leaves the building, stop them and ask "Are you sure you want to leave?
Please stay and take this free product". See how long your boss allows
you to harass his customers in that fashion, and, you will give away the
free products. Doesn't mean your pop up works, it means people are
taking the free product.

Besides, if you want to attempt to open a pop up when I leave your site,
by all means please do, I won't ever see it.
Anyway, I'm just a coder, and I do what the boss tells me to do, and he
does what the client tells him to do, and the customer is always right.

Unless the customer is wrong. My boss will tell me "The customer is
always right" and I will tell him "unless they are wrong" and the
conversation ends there. I guess I am also lucky to have a boss that
trust my opinion about my job?
At least until he discovers for himself that he's wrong.

And then figures out that the people he has employed didn't tell him
when they knew before hand?
 
F

fiziwig

I think altogether too much time and energy is being wasted on whether
a given harmless (if annoying) marketing gimmick is or is not "ethical"
or "moral", or whether or not I should have my membership in the human
race revoked for coding a popup, or whether or not my boss (who is a
wonderful guy whom I respect very much) is or is not bottom-feeding
scum.

Think what you want. Believe what you want. Act in the manner you
consider proper, and don't demonize those who disagree or imply that
opinions contrary to your own are the work of the devil and will be
eternally punished. Your religion may forbid popus but mine does not.
Does that mean we must engage in a holy war? Surely there are more
important things in life than lecturing those like me who have "fallen
from grace", or have not seen the light of the one true god of
programming.

Lighten up and get a life. Thus endeth my interest in this issue.

--gary
 
L

Lee

fiziwig said:
Think what you want. Believe what you want. Act in the manner you
consider proper, and don't demonize those who disagree or imply that
opinions contrary to your own are the work of the devil and will be
eternally punished. Your religion may forbid popus but mine does not.

You miss the point. The more people who abuse browsers, the
less comfortable people feel about shopping on the web and
the more restrictive browsers have to become.
Both of those effects are bad for all of us.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top