SessionStorage in a new window is not empty if you follow the link with target = "_ blank"

I see different types of HTML5 sessionStorage behavior when using Weblinks. Sometimes the sessionStorage of the first page is copied to TargetPage, sometimes I get an empty SessionStorage on TargetPage.

Can someone explain to me why this is so?

Given the following link:

<a href="TargetPage.html" target="_blank">link</a> 

When I open the link with the right mouse button → "open the link in a new tab", sessionStorage is empty in TargetPage. (Expected) But when I open the link with the usual left-click, sessionStorage is copied to TargetPage. (Unexpected)

Note. I have seen this behavior in Chrome and Firefox. In both cases, Internet Explorer 9 provides an empty sessionStorage. This is my expected behavior.

I created jsFiddle to demonstrate the behavior: http://jsfiddle.net/P9nUv/3/

Can anyone think of a cross-browser solution to provide an empty sessionStorage for new browser / Windows tabs, no matter how they were opened?

Any help is appreciated!

+6
cross-browser html5 session-storage
Jun 25 '13 at 12:24
source share
2 answers

IMHO:

I think the problem is in different browsing context . The W3C webStorage specification has a paragraph:

When a new document is created in a browsing context that has a top-level browsing context, the user agent must verify that the top-level browsing context has a session storage area for this beginning of the document

Document in this quote means a new page. Thus, if you open the same page in a new tab, it uses the same browsing context and the same sessionStorage, but if you open in a new window (ie target = "_ blank"), then the browsing context is different.

OR

The problem may consist of separate processor threads, so separate browsing context and separate sessionStorage s.

+1
Dec 25 '13 at 17:15
source share

Another ancient question, but I did not find the answers to this problem on this site, and I had the same problem with Firefox 44. I found a workaround, and you can find it here: https://stackoverflow.com/a/312619/ .

Hope this helps.

+1
Feb 24 '16 at 7:50
source share



All Articles