1. #1
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    226
    Vote Rating
    0
    Answers
    4
    abcdef is on a distinguished road

      0  

    Default Answered: Clearing cookies not functional?

    Answered: Clearing cookies not functional?


    I am trying to use the cookie clear method:

    Code:
    Ext.util.Cookies.clear(<Cookie Name>);
    where the path = / (so I am not passing it), but the cookie remains active in Safari, Chrome and Firefox.

    Is this a known issue?

  2. The dot isn't being added by Ext, that's the browser's doing.

    It does seem that the clear() method has some issues with domains though. Appears quite simple to workaround, just call set() with an expires date of new Date(0) and the other parameters set correctly.

  3. #2
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,078
    Vote Rating
    112
    Answers
    453
    skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold

      0  

    Default


    Could you give a specific example of how the cookie is set and what you're using to clear it? If it's set by a response header could you give an example of that?

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    226
    Vote Rating
    0
    Answers
    4
    abcdef is on a distinguished road

      0  

    Default


    Quote Originally Posted by skirtle View Post
    Could you give a specific example of how the cookie is set and what you're using to clear it? If it's set by a response header could you give an example of that?
    I am handling setting and clearing of cookies on the client side. So I am setting it as below:

    Code:
    Ext.util.Cookies.set(
        name,
        value,
        Ext.Date.add(new Date(), Ext.Date.DAY, 1000),
        '/',
        'a.b.com',
        true
    );
    I am trying to clear it as:

    Code:
    Ext.util.Cookies.clear(name);
    Any idea?

  5. #4
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,078
    Vote Rating
    112
    Answers
    453
    skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold

      0  

    Default


    Works for me, 4.0.2 and 4.0.5. Here's my test code if you want to give it a try yourself.

    Code:
    Ext.onReady(function() {
        Ext.getBody().update('<div></div>');
        var state = Ext.getBody().first();
        var clear = false;
    
        new Ext.button.Button({
            renderTo: Ext.getBody(),
            text: 'Click',
            handler: function() {
                if (clear) {
                    Ext.util.Cookies.clear('name');
                }
                else {
                    Ext.util.Cookies.set('name', 'value', Ext.Date.add(new Date(), Ext.Date.DAY, 1000), '/');
                }
    
                clear = !clear;
            }
        });
    
        setInterval(function() {
            state.update('Cookie value: ' + Ext.util.Cookies.get('name'));
        }, 100);
    });

  6. #5
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    226
    Vote Rating
    0
    Answers
    4
    abcdef is on a distinguished road

      0  

    Default


    Quote Originally Posted by skirtle View Post
    Works for me, 4.0.2 and 4.0.5. Here's my test code if you want to give it a try yourself.

    Code:
    Ext.onReady(function() {
        Ext.getBody().update('<div></div>');
        var state = Ext.getBody().first();
        var clear = false;
    
        new Ext.button.Button({
            renderTo: Ext.getBody(),
            text: 'Click',
            handler: function() {
                if (clear) {
                    Ext.util.Cookies.clear('name');
                }
                else {
                    Ext.util.Cookies.set('name', 'value', Ext.Date.add(new Date(), Ext.Date.DAY, 1000), '/');
                }
    
                clear = !clear;
            }
        });
    
        setInterval(function() {
            state.update('Cookie value: ' + Ext.util.Cookies.get('name'));
        }, 100);
    });
    Thank you for your response! So I see that when I explicitly pass the domain name 'a.b.com', it doesn't clear the cookie.

    When I pass in 'a.b.com' for the domain parameter, the cookie itself contains the domain parameter as '.a.b.com' (notice the dot before a.b.com) - In this case, the clearing does not work.

    But, when I pass in null for the domain parameter, the cookie displays the domain parameter as 'a.b.com' (without the dot) - In this case, the clearing works.

    Am I doing something wrong here?

  7. #6
    Sencha User skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,078
    Vote Rating
    112
    Answers
    453
    skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold skirtle is a splendid one to behold

      0  

    Default


    The dot isn't being added by Ext, that's the browser's doing.

    It does seem that the clear() method has some issues with domains though. Appears quite simple to workaround, just call set() with an expires date of new Date(0) and the other parameters set correctly.

  8. #7
    Sencha Premium Member
    Join Date
    Mar 2010
    Posts
    226
    Vote Rating
    0
    Answers
    4
    abcdef is on a distinguished road

      0  

    Default


    Quote Originally Posted by skirtle View Post
    The dot isn't being added by Ext, that's the browser's doing.

    It does seem that the clear() method has some issues with domains though. Appears quite simple to workaround, just call set() with an expires date of new Date(0) and the other parameters set correctly.
    Yep. That works. Thank you..