Page 1 of 1

Prevent visitors from leaving the domain

Posted: Mon Nov 24, 2008 11:43 pm
by max46
Hi,

I want to prevent visitors from leaving the website when they're on the page called 'count.php' only.
I mean if a visitor clicks on an external link on that page, nothing will happen. Only links with the domain as base url will be active.


tried with a javascript:
----------------------------------------------------------
function stopEvent(e) {
if(!e) var e = window.event;

//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = false;

//e.stopPropagation works only in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
return false;
}
-----------------------------
but that's not enough.


Any idea???

Thanks!

Re: Prevent visitors from leaving the domain

Posted: Tue Nov 25, 2008 3:30 am
by aceconcepts
Why do you want to do this?

Re: Prevent visitors from leaving the domain

Posted: Tue Nov 25, 2008 6:38 am
by Mark Baker
modify count.php so that any "external" links aren't written as links but as plain text.

Re: Prevent visitors from leaving the domain

Posted: Tue Nov 25, 2008 7:17 am
by Eran
To stop a link from redirecting you should be concerned only with preventDefault and not bubbling. Your script only runs preventDefault for Gecko based browsers (firefox), it should be something like this:

Code: Select all

 
function stopEvent(e) {
   if(!e) var e = window.event;
   e.preventDefault();
}
 
You still need to attach the event to all the links (A tags), which you can do by using the onclick handler or with DOM methods. For the latter I'd recommend a javascript library such as jQuery as there are many cross-browser differences in event handling.