View Full Version : Catching someone leaving the site
annunaki10
Oct 29th 2008, 11:48 am
I recently acquired an old site with a high bounce rate. I'm adding a lot of new stuff to the site and want to point people to it. So when they try to navigate away, i want to add a confirm prompt and tell them to check out the new stuff. While i know this is annoying, i want to have it up for a short period of time.
I know i can put a check on the onunload but how do i prevent the page from changing? By the time onunload runs, it's already leaving.
Thanks for your help.
dimitar christoff
Oct 30th 2008, 8:54 am
you need an event handler.
for example, mootools:
<script type="text/javascript">
// attach a key listener
Element.NativeEvents.beforeunload = 2;
window.addEvent("beforeunload", function(e) {
if (confirm("Are you certain you want to do this? Please stay...")) {
e.preventDefault();
}
});
</script>
but it can work w/o it also.
mind you, only modern browsers support beforeunload, rest is 'unload' which fires a little too late to stop it...
annunaki10
Oct 30th 2008, 12:00 pm
That block of code didn't work. I did find a block that does
<script language = "javascript">
function goodbye(e)
{
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation)
{
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload = goodbye;
</script>
The problem is this works when leaving the page. I want something that works only when trying to leave the site. If someone is going from one page to another, i don't want to bother them. I only want to bother them if they're going off to a new site.
you need an event handler.
for example, mootools:
<script type="text/javascript">
// attach a key listener
Element.NativeEvents.beforeunload = 2;
window.addEvent("beforeunload", function(e) {
if (confirm("Are you certain you want to do this? Please stay...")) {
e.preventDefault();
}
});
</script>
but it can work w/o it also.
mind you, only modern browsers support beforeunload, rest is 'unload' which fires a little too late to stop it...
dimitar christoff
Oct 30th 2008, 12:52 pm
what i posted is working but relies on the mootools js framework.
but i see the problem you are having--and frankly, it is impossible to know where they are headed, hence you can't tell if they are leaving your site or just moving between pages. you need to think of a better way of managing your bounce rate to prevent them from trying to leave in the first place....
annunaki10
Nov 12th 2008, 3:20 pm
Yeh that's what i was afraid of. I've already started bring bounce down by adding new content and chaing the look of the site. Thanks for the help though.
deathshadow
Nov 12th 2008, 9:30 pm
I would avoid doing this if at all possible. You are MORE likely to have people NEVER return to your site if you do this sort of thing than it is to increase your retention.
Goofy navigation tricks won't retain a userbase any more than a truckload of SEO trickery, stupid flash tricks or all those pretty pictures the nimrods who draw a .psd and have the nerts to call themselves designers churn out.
It's all about the content.
MMJ
Nov 13th 2008, 3:51 am
I would avoid doing this if at all possible. You are MORE likely to have people NEVER return to your site if you do this sort of thing than it is to increase your retention.
Goofy navigation tricks won't retain a userbase any more than a truckload of SEO trickery, stupid flash tricks or all those pretty pictures the nimrods who draw a .psd and have the nerts to call themselves designers churn out.
It's all about the content.
True, unless there is a reason why you are telling him to stay.
(gmail warns you if you leave when a ajax request is pending)
annunaki10
Nov 13th 2008, 6:33 am
yeh i figured that much. i was really against the idea of doing it so it's probably for the best that i cant keep track that specifically.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.