Cookie expires in MS Edge

I set Cookie with expiration date:

document.cookie = 'name=value;expires=' + d.toUTCString();

Code above works perfect by Firefox and Chrom, but not by MS Edge. By MS Edge expiration date not available. Could I fix it, or this is persistent Edge bug?

What is d?

Object of type Date.

There are many dates that fail when it comes to cookies.

Please supply more details.

This date of one year ahead - april 2020. I don’t think that is the problem.

Okay, and with what code are you calculating that one year ahead?

            var d = new Date();
            d.setSeconds(d.getSeconds() + parseInt(_cookieHidden.getAttribute('data-expires')));

            document.cookie = '{name}={value};expires={expires}'
                .replace('{name}', _cookieHidden.getAttribute('data-name'))
                .replace('{value}', value)
                .replace('{expires}', d.toUTCString());

But as I just said, that works fine by all browsers except of Edge.

So now we have 4 more problems to find information about.

  • a mystery _cookieHidden element
  • an unknown data-expires attribute
  • an unknown data-name attribute
  • and an unstated value variable

Can you please supply a simplified example so that we can realistically help you with it?

1 Like

I suspect .getSeconds doesn’t do what you think it does…

Yes, it doesn’t give the number of seconds since the last epoch. It would be getTime / 1000 that gives that.

Instead, getSeconds just gives a number ranging from 0 to 59.

Though of course, that isnt actually the problem here.

A rather important question, though: What domain are you trying to run this on? A TLD? Edge is known to silently drop cookies for TLD’s.

I’ve checked d.toUTCString() and that was correct. .getSeconds gives the seconds 0…59, .setSeconds makes automatically correction if given seconds number > 59.

No that is not TLD and cookie wasn’t dropped. Just expires doesn’t work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.