TheUnknown Posted January 15, 2008 Share Posted January 15, 2008 Any ideas on how to get a pop up to load only one time per user per 24 hours? <HEAD> <SCRIPT LANGUAGE="JavaScript"> function popup(URL) { day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=300,height=300,left = 362,top = 234');"); } </script> <BODY onLoad="javascript:popup('http://torrentstorage.com')"> Quote Link to comment Share on other sites More sharing options...
warran Posted January 15, 2008 Share Posted January 15, 2008 <HEAD> <SCRIPT LANGUAGE="JavaScript"> alert(getExpDate(1,0,0)); setCookie("test","111",getExpDate(1)); function popup(URL) { if(getCookieVal("test")==""){ day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=300,height=300,left = 362,top = 234');"); } } function getExpDate(days, hours, minutes) { var expDate = new Date(); if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number") { expDate.setDate(expDate.getDate() + parseInt(days)); expDate.setHours(expDate.getHours() + parseInt(hours)); expDate.setMinutes(expDate.getMinutes() + parseInt(minutes)); return expDate.toGMTString(); } } //utility function called by getCookie() function getCookieVal(offset) { var endstr = document.cookie.indexOf(";", offset); if(endstr == -1) { endstr = document.cookie.length; } return unescape(document.cookie.substring(offset, endstr)); } // primary function to retrieve cookie by name 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; } // store cookie value with optional details as needed function setCookie(name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } // remove the cookie by setting ancient expiration date function deleteCookie(name,path,domain) { if(getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } </script> <BODY onLoad="javascript:popup('http://torrentstorage.com')"> Quote Link to comment Share on other sites More sharing options...
TheUnknown Posted January 15, 2008 Author Share Posted January 15, 2008 Hi, is there a line our something i should edit On every page load a box pops up telling me the time and date Quote Link to comment Share on other sites More sharing options...
warran Posted January 15, 2008 Share Posted January 15, 2008 delete line 3 alert(getExpDate(1,0,0)); Quote Link to comment Share on other sites More sharing options...
TheUnknown Posted January 15, 2008 Author Share Posted January 15, 2008 Hi It looks like its setting the cookie. I went and deleted the test cookie but i didn't receive a popup afterwords Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted January 15, 2008 Share Posted January 15, 2008 http://javascript.internet.com/cookies/only-popup-once.html Quote Link to comment Share on other sites More sharing options...
warran Posted January 15, 2008 Share Posted January 15, 2008 try again <HEAD> <SCRIPT LANGUAGE="JavaScript"> function popup(URL) { if(getCookie("test1")==undefined){ day = new Date(); id = day.getTime(); eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=300,height=300,left = 362,top = 234');"); } setCookie("test1","111",getExpDate(1,0,0),"",""); //deleteCookie("test1","",""); } function getExpDate(days, hours, minutes) { var expDate = new Date(); if(typeof(days) == "number" && typeof(hours) == "number" && typeof(hours) == "number") { expDate.setDate(expDate.getDate() + parseInt(days)); expDate.setHours(expDate.getHours() + parseInt(hours)); expDate.setMinutes(expDate.getMinutes() + parseInt(minutes)); return expDate.toGMTString(); } } //utility function called by getCookie() function getCookieVal(offset) { var endstr = document.cookie.indexOf(";", offset); if(endstr == -1) { endstr = document.cookie.length; } return unescape(document.cookie.substring(offset, endstr)); } // primary function to retrieve cookie by name 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; } // store cookie value with optional details as needed function setCookie(name, value, expires, path, domain, secure) { document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } // remove the cookie by setting ancient expiration date function deleteCookie(name,path,domain) { if(getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } </script> <BODY onLoad="javascript:popup('http://torrentstorage.com')"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.