473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

A handy trick I discovered for closing popups

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,scro llbars=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,lo cation=0,directories=0,status=0,menubar=0,scrollba rs=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

Nov 21 '06 #1
14 1430
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

Nov 21 '06 #2
On 21 Nov 2006 11:01:24 -0800, "fiziwig" <fi*****@yahoo.comwrote:
>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.

--
Zilbandy - Tucson, Arizona USA <zi*@zilbandyREMOVETHIS.com>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Nov 21 '06 #3

Zilbandy wrote:
On 21 Nov 2006 11:01:24 -0800, "fiziwig" <fi*****@yahoo.comwrote:
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.

--
Zilbandy - Tucson, Arizona USA <zi*@zilbandyREMOVETHIS.com>
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

Nov 21 '06 #4
On 21 Nov 2006 15:32:04 -0800, "fiziwig" <fi*****@yahoo.comwrote:
>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. :)

--
Zilbandy - Tucson, Arizona USA <zi*@zilbandyREMOVETHIS.com>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Nov 21 '06 #5
fiziwig said the following on 11/21/2006 6:32 PM:
Zilbandy wrote:
>On 21 Nov 2006 11:01:24 -0800, "fiziwig" <fi*****@yahoo.comwrote:
>>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.

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.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 22 '06 #6
On Tue, 21 Nov 2006 20:58:00 -0500, Randy Webb
<Hi************@aol.comwrote:
>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.

--
Zilbandy - Tucson, Arizona USA <zi*@zilbandyREMOVETHIS.com>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
Nov 22 '06 #7

Randy Webb wrote:
fiziwig said the following on 11/21/2006 6:32 PM:
Zilbandy wrote:
>
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

Nov 22 '06 #8
Lee
fiziwig said:
>

Randy Webb wrote:
>fiziwig said the following on 11/21/2006 6:32 PM:
Zilbandy wrote:
>>
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!
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.
--

Nov 22 '06 #9
fiziwig said the following on 11/22/2006 11:12 AM:
Randy Webb wrote:
>fiziwig said the following on 11/21/2006 6:32 PM:
>>Zilbandy wrote:
>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!
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>

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

Randy Webb wrote:
fiziwig said the following on 11/22/2006 11:12 AM:
<snip>
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>

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

Nov 22 '06 #11
Lee
fiziwig said:
>

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

<snip>
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>

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

Nov 23 '06 #12
fiziwig said the following on 11/22/2006 6:59 PM:
Randy Webb wrote:
>fiziwig said the following on 11/22/2006 11:12 AM:

<snip>
>>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>
<snipped the signature that Google Groups shouldn't have quoted>
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?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '06 #13
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

Nov 23 '06 #14
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.
--

Nov 23 '06 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Harlan Messinger | last post by:
Can you help me figure out what to do about popups? Sometimes we develop web applications where popups make very good sense for precisely the same reasons they make sense in traditional...
2
by: Tom Szabo | last post by:
Hi, >>IE in Windows XP Service Pack 2 has a popup blocker that blocks unsolicited >>popups >>IE (other than Windows XP Service Pack 2) also has many add-ons (Google toolbar, >>Yahoo! toolbar,...
1
by: TEN TOD PSA | last post by:
you can trick ASP.NET into letting you declare methods with code blocks (how anybody can survive without this i have no idea - in classic asp i haven't written any html outside of a sub/method in 8...
4
by: bbass | last post by:
thanks to all that replyied to my previous post with the following code in question: <a href="merc.htm" target="_new_merc" onfocusout=window.close class="left_link"> i understand that the...
14
by: BGreene | last post by:
I was not going to post this but my someone thought it was funny, Write the shortest c statement that will "exchange" two unsigned ints. in place.
2
by: Peter Oliphant | last post by:
Sometimes it's hard to get straight when passing or storing or returning an instance of a class whether you are still dealing with the original object or a copy. For example, the '=' operator used...
4
by: Ed Jay | last post by:
I'm using the following simple js to open a popup window. var popwin; function launchwin(winurl,winname,winfeatures) { popwin = window.open(winurl,winname,winfeatures); } Using the following...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
1
by: Moe Sisko | last post by:
Using : ASP.NET 2.0, IE 7. This is a strange problem with popups not working in IE to remote sites, even though popups are allowed in IE. To reproduce, create web site with two pages,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.