HTML 5 - sessionStorage - values ​​overlap between pages in the same domain

Are session values ​​persisted based on site or based on page?

I am storing some values ​​in sessionStorage across two pages in the same domain as example.com/page1 and example.com/page2. Now when I change the values ​​on one page it somehow overlaps or affects the value on the other page. I am switching between pg1 and pg2 in one browser, one tab. And the key names are the same on both pages. It would be very difficult for me to create new keys for page 2, but tried to understand why this is the case. My env is Safari on Mac.

Also, another question, can we create session variables for the entierity of the site, not just the page? Several times I would like to store some values ​​from one page and check its values ​​across all pages of this site if the user is in a session.

Thank!

+3


source to share


2 answers


The session store is meant to be accessed from any page in the same domain, so the value of the variable is the same for both pages. Although this is only for that particular window or tab.



Link: http://dev.w3.org/html5/webstorage/#introduction

+2


source


You can also define a second sessionStorage key so that you have two completely different sessionStorage instances. SessionStorage resides throughout the site, but only within one tab / window.



It might also be helpful to look at the difference between localStorage and sessionStorage: HTML5 Local Storage vs. Session Storage

+1


source







All Articles