A handy trick I discovered for closing popups

Discussion in 'Javascript' started by fiziwig, Nov 21, 2006.

  1. fiziwig

    fiziwig Guest

    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
     
    fiziwig, Nov 21, 2006
    #1
    1. Advertising

  2. fiziwig

    fiziwig Guest

    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
     
    fiziwig, Nov 21, 2006
    #2
    1. Advertising

  3. fiziwig

    Zilbandy Guest

    On 21 Nov 2006 11:01:24 -0800, "fiziwig" <> 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 <>
    Dead Suburban's Home Page: http://zilbandy.com/suburb/
    PGP Public Key: http://zilbandy.com/pgpkey.htm
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    Zilbandy, Nov 21, 2006
    #3
  4. fiziwig

    fiziwig Guest

    Zilbandy wrote:
    > On 21 Nov 2006 11:01:24 -0800, "fiziwig" <> 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 <>
    > 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
     
    fiziwig, Nov 21, 2006
    #4
  5. fiziwig

    Zilbandy Guest

    On 21 Nov 2006 15:32:04 -0800, "fiziwig" <> 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 <>
    Dead Suburban's Home Page: http://zilbandy.com/suburb/
    PGP Public Key: http://zilbandy.com/pgpkey.htm
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    Zilbandy, Nov 21, 2006
    #5
  6. fiziwig

    Randy Webb Guest

    fiziwig said the following on 11/21/2006 6:32 PM:
    > Zilbandy wrote:
    >> On 21 Nov 2006 11:01:24 -0800, "fiziwig" <> 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/
     
    Randy Webb, Nov 22, 2006
    #6
  7. fiziwig

    Zilbandy Guest

    On Tue, 21 Nov 2006 20:58:00 -0500, Randy Webb
    <> 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 <>
    Dead Suburban's Home Page: http://zilbandy.com/suburb/
    PGP Public Key: http://zilbandy.com/pgpkey.htm
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
    Zilbandy, Nov 22, 2006
    #7
  8. fiziwig

    fiziwig Guest

    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
     
    fiziwig, Nov 22, 2006
    #8
  9. fiziwig

    Lee Guest

    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.


    --
     
    Lee, Nov 22, 2006
    #9
  10. fiziwig

    Randy Webb Guest

    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/
     
    Randy Webb, Nov 22, 2006
    #10
  11. fiziwig

    fiziwig Guest

    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
     
    fiziwig, Nov 22, 2006
    #11
  12. fiziwig

    Lee Guest

    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.


    --
     
    Lee, Nov 23, 2006
    #12
  13. fiziwig

    Randy Webb Guest

    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/
     
    Randy Webb, Nov 23, 2006
    #13
  14. fiziwig

    fiziwig Guest

    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
     
    fiziwig, Nov 23, 2006
    #14
  15. fiziwig

    Lee Guest

    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.


    --
     
    Lee, Nov 23, 2006
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr [MVP, MCSD]

    ASP.NET Security Vulnerability Discovered. Install the patch!

    Steve C. Orr [MVP, MCSD], Oct 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    354
    =?Utf-8?B?U3RldmVS?=
    Nov 11, 2004
  2. Replies:
    5
    Views:
    279
    Tor Iver Wilhelmsen
    Feb 15, 2007
  3. 1
    Replies:
    0
    Views:
    312
  4. 1
    Replies:
    5
    Views:
    295
    Diego Martins
    Feb 8, 2007
  5. Moe Sisko
    Replies:
    1
    Views:
    884
    George
    Aug 4, 2008
Loading...

Share This Page