Boards.ie uses cookies. By continuing to browse this site you are agreeing to our use of cookies. Click here to find out more x
Thread Closed  
 
 
Thread Tools Search this Thread
27-02-2010, 16:07   #1
kawadri
Registered User
 
Join Date: Feb 2010
Posts: 18
Javascript Code to stop user leaving Page

Hi,
I was wondering, I was searching on Google, I see this on websites like www.theaffiliatecode.com [Mod edit: Clicking on that link leads to a very annoying javascript jail], I want when someone tries to leave the page it says a message, when they click cancel they go onto another web page of my choice...

Last edited by Sparks; 28-02-2010 at 10:51.
kawadri is offline  
Advertisement
27-02-2010, 16:33   #2
Giblet
Registered User
 
Giblet's Avatar
 
Join Date: Oct 2001
Location: Dublin
Posts: 10,604
Wire up the onunload event.

<body onUnload="MyFunction()">

function MyFunction(){
do annoying crap here.
}

That page just pops up a confirmation dialog using
if(confirm('Do you want to leave?'))
{
//Do yes
}
else
{
//Do no
}
. I'd advise against using these. Any website that ever uses these will never be visited by me ever again.

Last edited by Giblet; 27-02-2010 at 16:35.
Giblet is offline  
(4) thanks from:
27-02-2010, 16:48   #3
kawadri
Registered User
 
Join Date: Feb 2010
Posts: 18
Reply

Quote:
Originally Posted by Giblet View Post
Wire up the onunload event.

<body onUnload="MyFunction()">

function MyFunction(){
do annoying crap here.
}

That page just pops up a confirmation dialog using
if(confirm('Do you want to leave?'))
{
//Do yes
}
else
{
//Do no
}
. I'd advise against using these. Any website that ever uses these will never be visited by me ever again.
Thanks, if they click cancel I want them to be redirected to another page, got any ideas? Also where do I put my text? Thanks
kawadri is offline  
27-02-2010, 20:38   #4
CreepingDeath
Registered User
 
CreepingDeath's Avatar
 
Join Date: Jun 2006
Posts: 3,872
Quote:
Originally Posted by kawadri View Post
I want when someone tries to leave the page it says a message, when they click cancel they go onto another web page of my choice...
Not very user friendly if you ask me.
CreepingDeath is offline  
27-02-2010, 21:09   #5
kawadri
Registered User
 
Join Date: Feb 2010
Posts: 18
Discount

Quote:
Originally Posted by CreepingDeath View Post
Not very user friendly if you ask me.
It gives them a discount
kawadri is offline  
Advertisement
28-02-2010, 03:31   #6
ronivek
Registered User
 
Join Date: Mar 2007
Location: Dublin
Posts: 229
Quote:
Originally Posted by kawadri View Post
It gives them a discount
Why not just have a clear banner/link/whatever which offers a discount from your main page?

If I visited a site, decided I wanted to browse away from the page and got any kind of popup when I tried to leave in all likelihood I would never return.
ronivek is offline  
28-02-2010, 04:18   #7
Evil Phil
Moderator
 
Evil Phil's Avatar
 
Join Date: Mar 2001
Location: West Indies
Posts: 7,111
Yeah, it's not one really. I'm not suprised you're not getting much help.
Evil Phil is offline  
28-02-2010, 10:41   #8
MyBusinez.com
Registered User
 
Join Date: Jan 2010
Posts: 88
Quote:
Originally Posted by kawadri View Post
Hi,
I was wondering, I was searching on Google, I see this on websites like www.theaffiliatecode.com, I want when someone tries to leave the page it says a message, when they click cancel they go onto another web page of my choice...
A bit of advice: If you want people to stay on your website preventing them from leaving is the worst way to do it as they will never visit again. You have to understand that on the internet, the user is in control, not the website.

There is no real way of preventing people from leaving your website anyway as they can always just pull the plug on their computer and if you prevent them from leaving they might think there is a virus on your website or a virus on their computer coming from your website.

You might as well stand at the door of your shop and not let people leave in order that they'll buy your product. Why not try offering them something that they'll like instead?
MyBusinez.com is offline  
28-02-2010, 10:51   #9
Gordon
Administrator
 
Gordon's Avatar
 
Join Date: Jul 2001
Posts: 27,555
Admin: Prison
kawadri, this kind of browser manipulation is unprofessional and will annoy users, I am quite angry at you for not putting a warning on that link tbh, firefox forced me to click ok 5 times when I closed the tab.

If you are the business owner and have to force people to stay on your site, rethink your business and web design, you are doing something wrong. If you are the web designer doing this for the business, tell them that it will annoy and alienate customers and advise them against this bullying course of action.

Last edited by Gordon; 28-02-2010 at 10:53.
Gordon is offline  
Advertisement
28-02-2010, 10:53   #10
Sparks
Category Moderator
 
Sparks's Avatar
 
Join Date: Apr 2003
Posts: 30,896
Quote:
Originally Posted by kawadri View Post
It gives them a discount
It'd have to be a very very large discount on something they're looking to purchase right then and there in order to not tick off whomever encounters it. Frankly, I think it's a bad idea that will do more to harm your site than to help it.
Sparks is offline  
28-02-2010, 11:19   #11
biko
Percolator
 
biko's Avatar
 
Join Date: Jul 2005
Location: Galway City
Posts: 37,314
Def a very bad idea. Put a contact number on the site so people can ring you and vent.
biko is offline  
28-02-2010, 16:10   #12
kawadri
Registered User
 
Join Date: Feb 2010
Posts: 18
It's a bad idea to put a phone number on a ClickBank product, the thing is when you visit certain sites you can tell that it is a clickbank product or not...

When the visitor sees that it's a clickbank product they try to navigate away to get a discount, I know the visitor is in control, I can't believe some are annoyed at me for not telling you that that website theaffiliatecode.com has a leaving message, I use firefox and I got one message saying to leave.

The reason why I am asking you is because I don't want to pay http://exitsplash.com/ 97 dollars for this code...

Take a look at http://exitsplash.com/ to see the benefits of this javascript code, plus that shop comment was quite funny but you're wrong, most stores you go into when you are about to leave without buying anything some will say "wait I will give you a discount" or something....
kawadri is offline  
28-02-2010, 16:12   #13
kawadri
Registered User
 
Join Date: Feb 2010
Posts: 18
Thanks for all the advice but this is what all cb products do...
kawadri is offline  
28-02-2010, 16:17   #14
5uspect
Moderator
 
5uspect's Avatar
 
Join Date: May 2006
Location: Back from Abroad.
Posts: 8,130
This is perhaps one of the most annoying things a website could do.
Not only does it open an annoying popup with associated warning prompt it plays audio without your control.

If a site did that to me I would never ever visit that site again.
5uspect is offline  
28-02-2010, 17:03   #15
ocallagh
Registered User
 
Join Date: Apr 2005
Posts: 3,643
Firefox + Greasemonkey + http://javascript.about.com/library/exitblock.user.js
ocallagh is offline  
Thanks from:
Thread Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search