Advertisement

01.08.2004 at 07:24AM PST, ID: 20844900
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

Convert date/time to expire cookie

Asked by Chris24 in JavaScript

Tags: ,

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(OrderingDownCApopupPath,'DownMaint','scrollbars=yes,toolbar=yes,location=yes,resizable=yes,width=600,height=530')
                  DownMaint.moveTo(60, 60);
                  DownMaint.focus()
            } else {
                   DownMaint.moveTo(60, 60);
                   DownMaint.focus()
                  DownMaint = window.open(OrderingDownCApopupPath,'DownMaint','scrollbars=yes,toolbar=yes,location=yes,resizable=yes,width=600,height=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*1000))
            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.donotshow.checked){
saveCookie('BlockWindow','Yes',30)}
if(!document.DoNotShow.donotshow.checked){
deleteCookie('BlockWindow')}
}

function checkBlocked() {
var blocked = readCookie('BlockWindow');
      if (blocked==null) {
      document.DoNotShow.donotshow.checked = false;
      }
      else {
      document.DoNotShow.donotshow.checked = true
      }
}Start Free Trial
[+][-]01.08.2004 at 07:31AM PST, ID: 10072071

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: cookie, expire
Sign Up Now!
Solution Provided By: ZeroPage
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.08.2004 at 07:31AM PST, ID: 10072073

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:34AM PST, ID: 10072092

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:36AM PST, ID: 10072113

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:37AM PST, ID: 10072127

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:39AM PST, ID: 10072141

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:45AM PST, ID: 10072189

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:47AM PST, ID: 10072222

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.08.2004 at 07:58AM PST, ID: 10072323

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32