Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Cookie script to LocalStorage?

  1. #11
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    In Safari Win, you can look at the cookies by clicking:

    edit > preferences > security > view cookies

    If your browser on iPad has that or an equivalent, do that. Find one of your cookies and check the expires date. If it's as expected, there's a bug in the browser or it's set to only hold a limited number of cookies. Even if it's expires is not set as expected there might still be a bug in the browser. But there might also or instead be a problem with the cookie setting code.

    I looked it over a little (I can still look at it further), it uses the toUTCString method. The toGMTString method is/was preferred, but I don't think there is any real difference, though there might be.

    See if you can find out that information, whether the expires date is set as expected or not.
    Last edited by jscheuer1; 07-08-2010 at 03:12 AM. Reason: spelling
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  2. The Following User Says Thank You to jscheuer1 For This Useful Post:

    pxlcreations (07-07-2010)

  3. #12
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Yeah, I've been checking the expire date on my Mac Safari and it still sets it to end at the end of the day. I don't know why, but I'm pretty sure it is not a browser bug, but instead a bug in the script. I'll change the UTC to GMT and see what happens.

    Well would you look at that, changing it to toGMTString makes it set a year ahead! Perfect! Thank you once again, I don't think anyone else would've found that.

  4. #13
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    That's pretty bizarre. I say because if I do:

    Code:
    <script type="text/javascript">
    var d = new Date();
    alert(d.toUTCString() === d.toGMTString());
    </script>
    in any browser (including Safari Win) I have, it alerts true.

    But I suppose it's possible that on the iPad it might be false.

    Try it and see.

    If it is false, I'd be interested in the difference. So then do:

    Code:
    <script type="text/javascript">
    var d = new Date();
    alert('UTC = ' + d.toUTCString() + '\nGMT = ' + d.toGMTString());
    </script>
    and see if you can spot the difference.

    Edit: Added Later:

    If there is no difference, then the script was OK as it was, just some caching issue going on. However, just to be on the safe side, stick with GMT.
    Last edited by jscheuer1; 07-09-2010 at 04:37 AM. Reason: add edit about 'no difference'
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #14
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Yeah, I still don't know why, but now the cookie menu in safari and firefox show that they will expire in 2011, so its working fine now.

    On a side note, is there a way I could have a link that would clear all the cookies from the site?

  6. #15
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I haven't tested either of these, but they should work (except perhaps for secure cookies, which yours are not) -

    To kill the cookies you have:

    Code:
    funtion killCookies(){
        $('.remember').each(function() {
            $.cookie(this.id, '', {expires: -1});
        });
        $('.draggable').each(function() {
            var draggable = $(this);
            $.cookie(this.id, '', {expires: -1});
            $.cookie('disp' + this.id, '', {expires: -1});
        });
    }
    To kill all cookies on a page:

    Code:
    function killAllCookies(){
    	var cookies = document.cookie.split(';'), i = cookies.length - 1;
    	for (i; i > -1; --i){
    		$.cookie(cookies[i].split('=')[0], '', {expires: -1});
    	}
    }
    Just be aware though, if you run either of these while the page is loaded, and then unload the page, new cookies will be set.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #16
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Ok, I set up the link and it's deleting the cookies, but when I reload the page they just come back, which is what you were saying here:

    Just be aware though, if you run either of these while the page is loaded, and then unload the page, new cookies will be set.
    Are there any ways to get around that?

  8. #17
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    To do that you have to remove the unload code. You can do that at least two ways:

    1. Code:
      $(window).unbind('unload');
      Which you could put at the start of either of the two kill functions from my last post.


    2. Or you could simply temporarily comment out the unload code from your script.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    pxlcreations (07-10-2010)

  10. #18
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    To do that you have to remove the unload code. You can do that at least two ways:

    1. Code:
      $(window).unbind('unload');
      Which you could put at the start of either of the two kill functions from my last post.


    2. Or you could simply temporarily comment out the unload code from your script.

    Works perfect! Thank you for all the help on this, is it ok if I PM you if I have any more questions?

  11. #19
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by pxlcreations View Post
    Works perfect! Thank you for all the help on this, is it ok if I PM you if I have any more questions?
    You're welcome. I like to reserve PM's for stuff that shouldn't be in the open forum, like links to pages you don't want indexed from the forum here. But for general ans specific help stuff I like it to be in the open forum where there are more liberal limits on the amount of text per message, attachments (no attachments in PM's), and others can learn from it too.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  12. #20
    Join Date
    Apr 2010
    Posts
    89
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default

    Ok, that's fine. So in that other post about positioning the Divs in the center of the screen, that was a result of having to change the "relative" to "absolute" in the cookie file. When it's set at "relative" and the page is reloaded, the divs are in totally different positions on the screen.

    So do you know how to make the remembered positions correct if I were to use relative?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •