PDA

View Full Version : FairWell popup on site exit (not page exit)


lkeane
09-14-2005, 04:43 AM
I am trying to launch a popup window when someone exits my site (as in when they press 'home' in their browser). I do not want the popup to launch when they click on an internal link.

I was able to get a simple script to work using 'onUnload'. The problem is that it opens a popup when the navigation menu is clicked (a link to another page on my site).

I wanted to exclude my domain from the onUnload function. Is this possible?

I am using JavaScriptKit's FairWell window launcher (http://www.javascriptkit.com/script/cut65.shtml):
<script>

/*
Fair well window launcher script
By JavaScript Kit (http://javascriptkit.com)
Over 200+ free scripts here!
*/

function openpopup(){
//configure "seeyou.htm and the window dimensions as desired
window.open("seeyou.htm","","width=300,height=338")
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function loadpopup(){
if (get_cookie('popped')==''){
openpopup()
document.cookie="popped=yes"
}
}

</script>

with <body onunload="loadpopup()">

Any ideas on how to exclude my domain?

_Aerospace_Eng_
09-14-2005, 04:50 AM
Read this thread http://www.codingforums.com/showthread.php?t=67821
be forewarned that doing what you are trying to do might make your visitors not go back to your site. It might also be blocked by a popup blocker.

lkeane
09-14-2005, 05:24 AM
OK so using this
function launchwin()
{
if (document.referrer == "" || document.referrer.indexOf("yourdomain.com") == -1)
{
window.open ("info.html", "info", "width=400, height=300, status=no");
}
}
wouldn't that be if I wanted the popup to open when they arrive? I want it to open when they leave. Is there a way to change 'referrer' to 'destination'? I dont think it will work how it is.

felgall
09-14-2005, 11:33 PM
1. Many people have document.referrer set to be always blank by their browser or firewall.

2. When leaving a web page you only know where the person is going next (onsite or offsite) if they are leaving the page by clicking a link in the page. If they leave the page by pressing the back button, selecting a bookmark, keying in a new URL, or closing their browser you have no way to tell that they are leaving your site.

3. Given 1 and 2 you could build the necessary code into the links on your page that transfer the person offsite.

lkeane
09-15-2005, 01:13 AM
I don't have any links that transfer the person offsite.

The only way they can leave is by "pressing the back button, selecting a bookmark, [or] keying in a new URL". However, onUnload seems to work in those instances.

The only problem is that I don't want onUnload to function when the internal links are clicked. How do I exclude my domain, is that possible?