Try this
Code:
<SCRIPT LANGUAGE="JavaScript">
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0)
break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
if(!(visit = GetCookie("visit")))
visit = 0;
visit++;
SetCookie("visit", visit, expdate, "/", ".your-domain-name.com", false);
var message;
if(visit == 1)
popup()
}
/////////////editable part///////////////////////////////////////
function popup(){
window.open('http://www.your-domain-name.com/popup.html','win1','width=550,height=440,resizable')
}
/////////////editable part///////////////////////////////////////
</script>
Here's how it works:
1.) Paste between the head tags on every page that you want it to pop-up when that page is left.
2.) Change the URL (highlighted in red) of the pop up to the location of it on your site.
3.) Put: OnUnload="DisplayInfo() at the very end of the BODY tag on every page that you use the JavaScript on. This is what it looks like in my BODY tag: <body bgcolor="#FFFFFF" OnUnload="DisplayInfo()">
3.) Fiddle around with the width and height settings (highlighted in green) to make sure that the window that opens isn't too big or too small. Temporarily disable cookies while testing the script in order to see the pop-up every time.
4.) Change your-domain-name.com to your actual domain. If you are hosted by a free web space provider like geocities.com, use your directory there. For example you would replace .your-domain-name.com with .yourisp.com/mysite/ -- notice the period in front of the domain.
5.) Upload the file. You're done.
On the page that you have pop up, just add the following:
Code:
<p>No thanks, <a href="javascript: self.close()">close
this window</a>.</p>
The cookie that writes to the computer will make it so that this pop-up never sows up again. You can make it so that it will come up every month, with a little bit of cookie know-how. I originally got this from what used to be sitepoint, webmaster-resoures.com.
Mike
Bookmarks