I have the following script to set a start date and time and an end date and time to display popup messages for our customers. These messages contain systems alerts, holiday messages .. etc. However, users were wanting to be able to turn off the popup once they saw them once. I wrote this ability in by placing a checkbox in the popup window that, when checked, writes a cookie. The next time they hit that page the window will not popup if the cookie exists. This all works fine but I want the cookie to expire at the same date and time that I put in for the popup to end. Below are my scripts. If someone could help, I would greatly appreciate it.
var OrderingDownStartCA = "1/01/2004 8:00:00 AM";
var OrderingDownEndCA = "1/10/2004 12:00:59 AM"; //<--I want to expire the cookie named blockWindow on whatever date and time is displayed here.
var OrderingDownCApopupPath = "../popups/popup_new.html"
//************************
**********
**********
**********
**********
**********
**********
****
// DO NOT EDIT BELOW THIS LINE //
//************************
**********
**********
**********
**********
**********
**********
****
function ordering_downCA() {
var TimeDifference1, TimeDifference2;
var interval = "M";
var rounding = true;
var start, end;
var Now = new Date();
start = OrderingDownStartCA;
end = Now;
TimeDifference1 = suycDateDiff( start, end, interval, rounding );
//alert(TimeDifference1);
start = Now;
end = OrderingDownEndCA;
TimeDifference2 = suycDateDiff( start, end, interval, rounding );
//alert(TimeDifference2);
var blocked = readCookie('BlockWindow');
if (blocked==null) { //<--If cookie does not exist, do popup
if ((TimeDifference1 >= 0) && (TimeDifference2 >= 0))
{
setFocusOrderingCA()
}
}
}
function setFocusOrderingCA() {
self.name = "mainWindow";
var DownMaint
if(DownMaint!=false){
DownMaint = window.open(OrderingDownCA
popupPath,
'DownMaint
','scrollb
ars=yes,to
olbar=yes,
location=y
es,resizab
le=yes,wid
th=600,hei
ght=530')
DownMaint.moveTo(60, 60);
DownMaint.focus()
} else {
DownMaint.moveTo(60, 60);
DownMaint.focus()
DownMaint = window.open(OrderingDownCA
popupPath,
'DownMaint
','scrollb
ars=yes,to
olbar=yes,
location=y
es,resizab
le=yes,wid
th=600,hei
ght=530')
}
}
function suycDateDiff( start, end, interval, rounding ) {
var iOut = 0;
// Create 2 error messages, 1 for each argument.
var startMsg = "Check the Start Date and End Date\n"
startMsg += "must be a valid date format.\n\n"
startMsg += "Please try again." ;
var intervalMsg = "Sorry the dateAdd function only accepts\n"
intervalMsg += "d, h, m OR s intervals.\n\n"
intervalMsg += "Please try again." ;
var bufferA = Date.parse( start ) ;
var bufferB = Date.parse( end ) ;
// check that the start parameter is a valid Date.
if ( isNaN (bufferA) || isNaN (bufferB) ) {
alert( startMsg ) ;
return null ;
}
// check that an interval parameter was not numeric.
if ( interval.charAt == 'undefined' ) {
// the user specified an incorrect interval, handle the error.
alert( intervalMsg ) ;
return null ;
}
var number = bufferB-bufferA ;
// what kind of add to do?
switch (interval.charAt(0))
{
case 'd': case 'D':
iOut = parseInt(number / 86400000) ;
if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
break ;
case 'h': case 'H':
iOut = parseInt(number / 3600000 ) ;
if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
break ;
case 'm': case 'M':
iOut = parseInt(number / 60000 ) ;
if(rounding) iOut += parseInt((number % 60000)/30001) ;
break ;
case 's': case 'S':
iOut = parseInt(number / 1000 ) ;
if(rounding) iOut += parseInt((number % 1000)/501) ;
break ;
default:
// If we get to here then the interval parameter
// didn't meet the d,h,m,s criteria. Handle
// the error.
alert(intervalMsg) ;
return null ;
}
return iOut ;
}
function saveCookie(name,value,days
) {
if (days) {
var date = new Date();
date.setTime(date.getTime(
)+(days*24
*60*60*100
0))
var expires = "; expires="+date.toGMTString
()
}
else expires = ""
document.cookie = name+"="+value+expires+"; path=/"
}
function readCookie(name) {
var nameEQ = name + "="
var ca = document.cookie.split(';')
for(var i=0;i<ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length)
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,
c.length)
}
return null
}
function deleteCookie(name) {
saveCookie(name,"",-1)
}
function writeCookie() {
if(document.DoNotShow.dono
tshow.chec
ked){
saveCookie('BlockWindow','
Yes',30)}
if(!document.DoNotShow.don
otshow.che
cked){
deleteCookie('BlockWindow'
)}
}
function checkBlocked() {
var blocked = readCookie('BlockWindow');
if (blocked==null) {
document.DoNotShow.donotsh
ow.checked
= false;
}
else {
document.DoNotShow.donotsh
ow.checked
= true
}
}
Start Free Trial