Link to home
Start Free TrialLog in
Avatar of egoselfaxis
egoselfaxis

asked on

How can I modify my javascript to trigger the exit popup when a person closes the browser window?

I have the following exit popup javascript on one of the websites that I manage:

-------------- SNIP -----------------

      _doItThisTime = true;
      window.onbeforeunload = function() {
            if(_doItThisTime) {
                  _doItThisTime = false; // Do It next time : No !
                  if(confirm("Thanks for visiting, please become a fan and follow Harrison Crane on Facebook.")) {
                        setTimeout('document.location.href="http://www.facebook.com/pages/Miami/Harrison-Crane-Service/222776190641?ref=search&sid=1048623567.1916819466..1"',50);
                        return;
                  }
            }
      }

-------------- SNIP -----------------

It works fine, -- however, .. it does NOT work when the person closes the tab / browser.  The confirmation dialog is displayed, .. but clicking on "OK" does not take you to the facebook page.  Instead, the tab / browser just closes and that's it.  

Is there any way that I can update the above javascript so that clicking on "OK" takes you to the facebook page when the person closes the tab / browser? If so, how?

Thanks,
- Yvan


Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

No. And that is the way it should be.
How annoyed would you be if websites decided you were not allowed to close the browser?
And how annoyed would you be if it was the same page that loaded when you tried to leave or close?

Let the user leave when the user wants to leave.

The slickest workaround was to pop a div when the user moved his mouse direction top right corner.

I can show you that if you want
>Is there any way that I can update the above javascript so that clicking on "OK" takes you to the facebook page when the person closes the tab / browser? If so, how?
build your own browser with your own rules !
Yes mplungjan is right as usual !

(no points for this brillant anwser please :))
I may be right, but I do not get many chances to be right between you and Hielo.
It would be very nice to just get a FEW questions left over once in a while...
Avatar of egoselfaxis
egoselfaxis

ASKER

I appreciate your prompt replies, --- but note that I am spawning a confirmation dialog asking the user if they do or not not want to visit the facebook page:

http://www.harrisoncrane.com/

(try typing in a different url and hiting enter to see it in action)

I was just wondering if there was a way to take them to the facebook page when they click on the OK button within that dialog (when it's triggered by them closing the tab or browser window).

No?

- yg
I'm far away of hielo, the man is bad when he have the time to play...
Most of time I don't answer when I see you start answer but seems it's not suffisant :o(
Here I just want to confirm what you said to help close this frequent question
See you soon Boss
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok .. thanks guys.  I had a feeling that might be the definitive answer.

- yg
what if we want to execute a method that could clear all values, cookies and stuff off the user page??
may that be possible? i am trying to do this sort of execution upon tab closing however i have no success.
Can you ask a separate question?