I want to set a cookie using javascript, which would be available for all the tabs in browser.
I have used document.cookie = "tracker=ABC"
Even I have tried to set the path also, but result remained same
document.cookie = "tracker=ABC;path=/"
However, this seems applicable only to the tab where it was set. This cookie is not visible to other tabs in the browser..
Also, I am not very clear with the path concept in cookies. Would be great if someone can tell me about it's use as a secondary answer
Regards,
SAP Learner
So my question is: How can I set a cookie which would be applicable for all the tabs in the browser
I want to set a cookie using javascript, which would be available for all the tabs in browser.
I have used document.cookie = "tracker=ABC"
Even I have tried to set the path also, but result remained same
document.cookie = "tracker=ABC;path=/"
However, this seems applicable only to the tab where it was set. This cookie is not visible to other tabs in the browser..
Also, I am not very clear with the path concept in cookies. Would be great if someone can tell me about it's use as a secondary answer
Regards,
SAP Learner
So my question is: How can I set a cookie which would be applicable for all the tabs in the browser
Share Improve this question asked Sep 27, 2018 at 12:07 SAP LearnerSAP Learner 611 gold badge5 silver badges17 bronze badges1 Answer
Reset to default 5A cookie is not linked to a browser tab, but to a domain and its sub-domains.
If you couldn't create a "cross-tab" cookie, it's likely because the domains are different. It's an obvious security rule implemented by all browsers, that prevents domains from accessing other domains cookies.
If the domains are the same, then it works and you can verify it by yourself:
- open a tab, then open some website
- create some cookie with
document.cookie = "test"
in the console - open another tab, then open the same website
- type
document.cookie
in the console and you'll be able to see thetest
cookie