Tom Sebastian
Tom Sebastian

Reputation: 3433

scope difference between document and document.cookie

I have a simple doubt here:

document object scope is within a browser tab: I meant If I set document.tab1 ='tab1' in one browser tab It won't be available in other tabs.

But document.cookie is different, it persists across tabs.

But it is defined as a property of document, still if I add one entry in cookie from one browser tab, this entry can be accessed from other tabs.I understood like document object scope is within a tab.But here one document's property is shared between others. I know there are similar instances available for document or window objects, which are default properties or objects.

Why cookie like objects having scope across browser tabs, defined as a property of objects which have scope restricted within a tab like document?

Or correct my understanding.

Upvotes: 0

Views: 357

Answers (1)

Bergi
Bergi

Reputation: 664620

Why cookie-like objects having scope across browser tabs, defined as a property of objects which have scope restricted within a tab like document?

They don't. Each tab does have its own document.cookie, localStorage or window.name. They run in different (JS) environments, as parts of different event loops.

Of course, each of those getters/setters accesses the same domain-, page- or tab-specific attribute that the browser manages, but it's just a JS interface to it; and as such it is located on some JS object in the JS runtime.

Upvotes: 1

Related Questions