Home > Programming, Servers & Scripts >

Exit Pops & Browser Issues (4)


01-23-2013 01:31 AM #1 profitable ()
Exit Pops & Browser Issues

I use a pretty standard exit pop script I picked up a long time ago. I just realized that it only actually loads the exit pop page correctly on Firefox (on mac) and IE (on Windows).

Most browsers don't show the correct Alert text (WAIT!!! Don't leave, etc). It just asks if you want to "Stay on Page" or "Leave page".

Seems that:
Windows Firefox: Only says to either "Stay on Page" or "Leave page" but does redirect
Windows Chrome: Only says to either "Stay on Page" or "Leave page" but does NOT redirect
Windows IE: Works Perfectly

Mac Safari: "Stay on Page" or "Leave page" but does NOT redirect
Mac Chrome: "Stay on Page" or "Leave page" but does NOT redirect
Mac Firefox: Works Perfectly

Does anyone know if there is an updated script that will work properly on more browsers? I'm sure I'm leaving money on the table.

Below is my current code. Thanks!

Code:
<script type="text/javascript" language="javascript">
var areYouReallySure = false;
var internalLink = false;
function areYouSure() {
if(allowPrompt)
   {
if (!areYouReallySure && !internalLink && true) {
areYouReallySure = true;
location.href="http://url.com"
return "WAIT!!\n\nAre you sure you want to leave?!\n\nClick cancel to claim your product now.\n\nClick ***CANCEL*** now!\n\n";


}
}

   else
   {
      allowPrompt = true;
   }
}

var allowPrompt = true;
window.onbeforeunload = areYouSure;


function NoPrompt()
{
   allowPrompt = false;
}
</script>


01-23-2013 11:15 AM #2 caurmen (Administrator)

This (popping a custom message) turns out to be a non-trivial problem: Firefox, in particular, is no longer very enthusiastic about custom exit popups.

This JQuery code seems to work - note that you'll need to add the logic to not pop the popup when users click a link. (Here's a good guide to that) :

Code:
$(window).bind('beforeunload', function() {
    if(/Firefox[\/\s](\d+)/.test(navigator.userAgent) && new Number(RegExp.$1) >= 4) {
        if(confirm("Are you Sure do you want to leave?")) {
            history.go();
        } else {
            window.setTimeout(function() {
                window.stop();
            }, 1);
        }
    } else {
        return "Are you Sure do you want to leave?";
    }
});


01-23-2013 09:18 PM #3 profitable ()

Thanks for the link. I just went through it all and tested - now the custom exit pop text is working --- BUT --- still can't seem to get the page to redirect on exit pop.

Example Flow:

  1. User visits my page
  2. User tries to leave and gets a "WAIT!! don't leave" exit pop
  3. User decides to stay and is redirected to exit.php which has different presell information for them to read.


It's #3 that I'm still having trouble with on multiple browsers.

I tried adding: location.href="http://msn.com" (msn.com is merely a placeholder) in there and it still wont redirect. (my code below)

Code:
<script type="text/javascript">
     var popit = true;	 
     window.onbeforeunload = function() { 
          if(popit == true) {
               popit = false;
			   location.href="http://msn.com"
			   return "WAIT!! Don't leave?\n\nClick ***CANCEL*** and don't miss out on these great offers!\n\n"; 
          }
     }
</script>
It appears it could work by using the Fancybox code and creating a function to go to msn.com instead of loading the fancybox... but alas, I'm a bad coder and am not sure how to make it happen.

Much thanks.


01-24-2013 01:01 PM #4 karimelm (Member)

Redirect in the onbeforeunload is disabled in i think chrome, safari and even firefox / IE10 now. You can still do a div overlay (ajax), which basically means you will end up loading another page and load the overlay in the onbeforeunload function. Here's some inspiration: http://www.andysowards.com/blog/2008...-on-page-exit/

About the message only showing Stay on page or leave page options. That occurs with Firefox, chrome and safari if i recall correctly, you can solve that by adding a alert() before your return "blabl" line. In some browsers this will like double serve the message though (IE will show the alert, and the text in your return "blabla" line).


Home > Programming, Servers & Scripts >