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!
Prevent visitors from leaving the domain
Moderator: General Moderators
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: Prevent visitors from leaving the domain
Why do you want to do this?
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Prevent visitors from leaving the domain
modify count.php so that any "external" links aren't written as links but as plain text.
Re: Prevent visitors from leaving the domain
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:
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.
Code: Select all
function stopEvent(e) {
if(!e) var e = window.event;
e.preventDefault();
}