Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  28] [ 4]  / answers: 1 / hits: 16679  / 13 Years ago, mon, april 18, 2011, 12:00:00

Say I have two apps, www.test.com and sub.test.com, now in sub.test.com, I create a window to load www.test.com with codes like :



window.open('www.test.com'); 


So the window just popup and load www.test.com successfully.

Then I set a cookie in sub.test.com, say uname=wong2;domain=.test.com, I've learned that with set to domain=.test.com, all sites with domain test.com(such as www.test.com, aaa.test.com, test.com) can read the cookie.



But when I try to load the cookie from the window that just popup with www.test.com, it can't get it.



Then I found that if I don't use window.open but directly open www.test.com in browser, it works.



So is there some restrictions on window.open and cookie?


More From » browser

 Answers
11

just check how you set the cookie:



var domain = 'test.com';
var expires = (function(days){
date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
return date.toUTCString();
})(5);
var name = 'myCookie';
var path = '/';
var value = 'foo';

document.cookie = name + = + encodeURIComponent(value) + ; expires= + expires + ; path=' + path + '; domain= + domain + ;;

[#92669] Friday, April 15, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaydenathaliam

Total Points: 676
Total Questions: 102
Total Answers: 103

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;