i would need a feature, when a user closes out of the site they are prompted to bookmark the site. if they have choosen to bookmark the site in the past they will not prompted for the bookmark.
@felgallOct 07.2005 — #Javascript is not able to access anything outside of the web page. It is therefore unable to see if a bookmark already exists. Javascript is also unable to generate bookmarks automatically, only JScript is able to do that (IE only).
Also when someone closes their browser down there would be insufficient time for such a script to run in any case.
@felgallOct 10.2005 — #On my page http://javascript.about.com/library/blfav.htm I have a script that will add a bookmark link to the page in IE and instructions on how to bookmark in Mozilla/Firefox/Netscape and Opera.
@jmaresca2005authorOct 10.2005 — #thanks but i am already able to write a bookmark script in javascript, trying to figure out that extra functionality was the real task. thanks again ?
@konithomimoOct 10.2005 — #Below is a simple code that will bring up the bookmark window in IE, and will alert the user to press ctrl + c to bookmark the site in netScape. At the end of the code you can change the value of 'renewal' to however many days you want it to be before the user is asked to bookmark your site again.
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 = (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" : ""); }
var url = "http://www.javascript-page.com"; var title = "Nic's JavaScript Page";
if (GetCookie("bmark") == null) {
if (document.all) { window.external.AddFavorite (url,title); }
if (document.layers) { bktext = open("", "displayWindow", "width=200,height=100,status=no,toolbar=no,menubar=no");
bktext.document.open(); bktext.document.write("<html><body bgcolor='white' text='black'>" +"Please Bookmark this Page. " +"Press CTRL+C after closing.<br><br>" +"<a href='javascript:self.close();'>Close this window</a>"); bktext.document.write("</font></body></html>"); bktext.document.close() ; }
var renewal = 30; //once a user has bookmarked your page they will not be asked to for another 30 days. var exdate = new Date (); exdate.setTime(exdate.getTime() + (renewal*24*60*60*1000)); SetCookie('bmark','book',exdate); }