How to Display a Website Exit Message

Navigation

Sponsors

Website Exit Message

Save this to Del.icio.us

This script will allow you to display a message to the visitor as they leave the site. It can be used to suggest another site that may be of interest to the visitor etc...


Select all (Ctrl + A) the text script INSIDE of this text box directly below and copy it to your clipboard (Ctrl + C).

Open your webpage that you want the website exit message to load in a program such as Wordpad or Notepad and paste the above text (Ctrl + V) in between the HEAD Tags of the document.

The head of your webpage should now look like the code directly below. Edit the RED text only to reflect the web address for the website exit message that will be loaded if the viewer chooses...

<HEAD>

<script language="JavaScript">
<!--

function CreateCookie(name, value, expiredays)
{
var todayDate = new Date();
todayDate.setDate(todayDate.getDate() + expiredays);
document.cookie = name + " = " + value + "; expires=" +
todayDate.toGMTString() + ";";
}

function ReadCookie(cookiename)
{
var numOfCookies = document.cookie.length;
var nameOfCookie = cookiename + "=";
var cookieLen = nameOfCookie.length;
var x=0;
while (x <= numOfCookies)
{
var y = (x + cookieLen);
if (document.cookie.substring(x, y) == nameOfCookie)
return(ExtractCookieValue (y));
x = document.cookie.indexOf(" ", x) + 1;
if (x == 0)
break;
}
return null;
}

function ExtractCookieValue(val)
{
if ((endOfCookie = document.cookie.indexOf(";",val)) == -1)
{
endOfCookie = document.cookie.length;
}
return unescape(document.cookie.substring(val, endOfCookie));
}

function GoodBye()
{

// This is what the prompt will ask the visitor when they leave your website.

if (confirm(" Would you like to visit another webmasters resource before leaving? "))
{

// This is what the prompt will say if they choose to see what you asked above.

alert(" Thank you! ");
window.open("http://www.websiteyouwanttoload.com");
}
else
{

// This is what the prompt will say if they choose to not see what you asked

alert(" See you again Good Luck! ");
return false;
}
}

function MainGoodBye()
{
var userCookie = ReadCookie("_chups");
if (userCookie == null)
{

// User is here at first time
// propose to visit site

GoodBye();
//create coockie key (30 days)
CreateCookie("_chups", 1, 30);
}
}
//-->
</script>

</HEAD>

Now you must tell the website that you want website exit message to load when the visitor exits your page. To do that include this line into yout <BODY> tag.

<body onunload="MainGoodBye()">

After you have embedded the Head script into your page and you have added the body code correctly, you are ready to upload your pages!


[ Back to Website Tools and Tutorials ]


| Forums | Search | Donate | Links | Contact | Scripts | Templates |
Copyright © 2008 SiteToolCenter.com

Website Design

Best Viewed With Mozilla FireFox