sessionStorage on new window isn't empty, when following a link with target="_blank"
Asked Answered
C

2

13

I see different behaviors of the HTML5 sessionStorage when following Weblinks. Sometimes the sessionStorage of the first page is being copied to the TargetPage, sometimes I get an empty sessionStorage on the TargetPage.

Can anyone explain me, why this is the case?

Given the following link:

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

When I open the link with a right-click -> "open link in new Tab", the sessionStorage is empty on the TargetPage. (Expected) But when I open the link with a normal left-click, the sessionStorage gets copied over to the TargetPage. (Unexpected)

Note: I've seen this behavior in Chrome and Firefox. Internet Explorer 9 provides an empty sessionStorage in both cases. This is my expected behavior.

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

Can anyone think of a cross-browser solution to ensure an empty sessionStorage for new Browser Tabs/Windows, no matter how they've been opened?

Any help is appreciated!

Cakewalk answered 25/6, 2013 at 12:24 Comment(0)
B
6

IMHO:

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

When a new Document is created in a browsing context which has a top-level browsing context, the user agent must check to see if that top-level browsing context has a session storage area for that document's origin

Document in this quote means new page. So it means if you open in new tab the same page it use the same browsing context and the same sessionStorage, but if you open in new window (ie target="_blank") the browsing context is different.

OR

The problem can be of separate CPU threads, so separate browsing context and separate sessionStorages.

Bearnard answered 25/12, 2013 at 17:15 Comment(1)
I think it might be this case: When a new top-level browsing context is created by a script in an existing browsing context, or by the user following a link in an existing browsing context, or in some other way related to a specific Document, and the creation is not a new start for session storage, then the session storage area of the origin of that Document must be copied into the new browsing context when it is created. From that point on, however, the two session storage areas must be considered separate, not affecting each other in any way.Swam
A
3

Once again an ancient question but I didn't find any answers to this problem on this site and I just had this same problem with Firefox 44. I found a workaround and you can find it here: https://mcmap.net/q/120979/-sessionstorage-is-not-empty-when-link-opened-in-new-tab-in-internet-explorer

Hope this helps.

Alicia answered 24/2, 2016 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.