I need help with javascript cookies

Discussion in 'JavaScript' started by illinifan91, Sep 29, 2008.

  1. #1
    So i am working on my school's webpage and i have created a very small script with javascript that i use to show and hide a group of news articles. The problem is i dont know anything about cookies and wanted to make it so that if they close the news items it sets a cookie so that the next time they come back to the page it isnt open or vice versa. could somebody please help me with this.

    the html code:
    the javascript:

     
    illinifan91, Sep 29, 2008 IP
  2. needHelp?

    needHelp? Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I recommend jsCookie,
    It could simplify your handling of javascript cookies.
    http://codecanyon . net/item/jscookie-easy-to-use-javascript-cookie-library/308627 - (remove spaces)

    Now for the solution:
    var jsCookie = new jsCookie;
    //This will create a cookie that will expire in 30 days.
    //Add this code when user clicks to close the headline.
    jsCookie.create("headlineClosed","yes",[0,30,0,0]);
    PHP:
    ----------------------------------------------
    //Add this code after dom is ready:
    if(jsCookie.read("headlineClosed")=="yes"){
    //close headline
    }else{
    //keep open
    }
    PHP:
    Regards
     
    needHelp?, Aug 25, 2011 IP