Bookmark on Exit, but ONLY shown every 7 Days

They have: 1 posts

Joined: Sep 2008

Hello,

I would like to add an external javascript file that I can load in my header that will popup on exit, asking if the user would like to bookmark this site and / or page.

I also would like this to not show up EVERY time a user visits the site (preferably once a week).

I have found several codes to do this is all separately, but I would like it all in one and can't seem to get the code right as nothing I seem to do works at all.

Can anyone put this together for me?

1. Load ONLY on SITE exit (ie. browser close "x" or new address)

2. Cookie based ONLY show once every 7 days

3. If possible, don't show popup if user has "LOGGED-IN" prior to exit.

- Will have to pass a variable to the script later when I figure out which platform I decide to use, but feel that Members would obviously not want to see this.

4. On Exit popup, allow user to bookmark, main site address and also "page address" if they only desire that specific page.

5. Work on all platforms (IE, Mozilla, etc.)
- From what I understand with Mozilla is that javascript can only produce a CTRL-D to bookmark option popup. If that is true, then this is fine, but if there is way to show the same "Add to Favorites" as in IE, then I would like to have that option.

Here are the scripts I found:

-==============-
BOOKMARK ON EXIT
-==============-

<script type="text/javascript">
function bookmarksite(title,url){
if (window.sidebar)
window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
}
else if(document.all)// ie
window.external.AddFavorite(url, title);
}
</script>

onUnload="javascript:bookmarksite('YOURWEBSITETITLE', 'YOURWEBSITEURL')"'

-=================-
BOOKMARK EXACT PAGE
-=================-

var txt = "Bookmark Us"
var url = this.location;
var who = document.title;
var ver = navigator.appName
var num = parseInt(navigator.appVersion)
if ((ver == "Microsoft Internet Explorer")&&(num >= 4)) {
document.write(''+ txt + '')

}else{
txt += " (Ctrl+D)"
document.write(txt)
}

-=========================-
7 DAY POPUP COOKIE MANAGER
-=========================-

var expDays = 7;

var page = "popup.html";
var windowprops = "width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

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 = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? 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 DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
} else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
window.open(page, "", windowprops);
} else {
count++;
SetCookie('count', count, exp);
}
}

window.onload=checkCount;

-=============================================-

If anyone can figure out a way to put all these together into one script and also add a check (if possible) to negate any popups if visitor has logged in prior to exiting please let me know!

Thanks again Smiling

decibel.places's picture

He has: 1,494 posts

Joined: Jun 2008

Hi yackso,

I think we can cook something up with these ingredients - or if not use a db field

PM me with your info

It's a rite of passage here to post an Introduction Smiling so everybody can get to know you!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.