1

I'm using this code to save cookies:

function saveCookie(name,value) {
        var date = new Date();
        date.setTime(date.getTime()+(60*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
        document.cookie = name+"="+value+expires+"; path=/";
        }

My problem is that it saves the cookie with domain "example.com" and I want to write them to ".example.com" so I can also read them from subdomains. This is easy to do with PHP but I don't know how to do it with javascript. How can I add a dot before the domain when I save the cookie?

lisovaccaro
  • 27,544
  • 92
  • 235
  • 388
  • possible duplicate of [setting cross-subdomain cookie with javascript](http://stackoverflow.com/questions/4713019/setting-cross-subdomain-cookie-with-javascript) – Bergi Jul 18 '12 at 21:13

2 Answers2

0

You already have path in there, domain is specified in the same way.

Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540
0

To permit reading from other sub-domains, try:

'; path=/; domain=.'+window.location.host;
stealthyninja
  • 9,960
  • 11
  • 45
  • 55
Lyn Headley
  • 10,260
  • 3
  • 30
  • 35