I want to open new window by using window.open and I want to set new cookie for that new window . I have tried to set cookie by using below code
window.open("https://mysite.n")
var expires = (function(days){
date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 *
1000));
return date.toUTCString();
})(5);
document.cookie ="mytestcookie=testcookie; expires="+expires+"; path=/";
After this code execution . When I tried to get this cookie in new window I am getting undefined . Please help to set cookie in new window .
Thanks in Advance .
You need to set the cookie before you load the new page. Just reorder your code so window.open is last.
This assumes that new page is on the same origin as the current page. If it isn't, you can't set a cookie. It would be a major security problem if you could record data in a datastore belonging to someone else's website.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With