Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > A handy trick I discovered for closing popups

Reply
Thread Tools

A handy trick I discovered for closing popups

 
 
fiziwig
Guest
Posts: n/a
 
      11-21-2006
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

 
Reply With Quote
 
 
 
 
fiziwig
Guest
Posts: n/a
 
      11-21-2006
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

 
Reply With Quote
 
 
 
 
Zilbandy
Guest
Posts: n/a
 
      11-21-2006
On 21 Nov 2006 11:01:24 -0800, "fiziwig" <(E-Mail Removed)> wrote:

>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 <(E-Mail Removed)>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
 
Reply With Quote
 
fiziwig
Guest
Posts: n/a
 
      11-21-2006

Zilbandy wrote:
> On 21 Nov 2006 11:01:24 -0800, "fiziwig" <(E-Mail Removed)> wrote:
>
> >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 <(E-Mail Removed)>
> 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

 
Reply With Quote
 
Zilbandy
Guest
Posts: n/a
 
      11-21-2006
On 21 Nov 2006 15:32:04 -0800, "fiziwig" <(E-Mail Removed)> wrote:

>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 <(E-Mail Removed)>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-22-2006
fiziwig said the following on 11/21/2006 6:32 PM:
> Zilbandy wrote:
>> On 21 Nov 2006 11:01:24 -0800, "fiziwig" <(E-Mail Removed)> wrote:
>>
>>> 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/
 
Reply With Quote
 
Zilbandy
Guest
Posts: n/a
 
      11-22-2006
On Tue, 21 Nov 2006 20:58:00 -0500, Randy Webb
<(E-Mail Removed)> 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.


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 <(E-Mail Removed)>
Dead Suburban's Home Page: http://zilbandy.com/suburb/
PGP Public Key: http://zilbandy.com/pgpkey.htm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~
 
Reply With Quote
 
fiziwig
Guest
Posts: n/a
 
      11-22-2006

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

 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      11-22-2006
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.


--

 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      11-22-2006
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: A Handy Trick aracARI Computer Security 9 12-31-2008 05:47 PM
Re: A Handy Trick nemo_outis Computer Security 0 12-30-2008 05:20 PM
A Handy Trick nemo_outis Computer Security 0 12-29-2008 07:52 PM
Popups not working, even if Popups are allowed in IE Moe Sisko ASP .Net 1 08-04-2008 03:33 PM
Being pestered by popups / word lastig gevallen door popups. Martijn Computer Support 21 11-03-2004 06:45 PM



Advertisments