在新窗口上的sessionStorage不为空时,当跟随具有target =“_blank”的链接时, [英] sessionStorage on new window isn't empty, when following a link with target="_blank"

查看:780
本文介绍了在新窗口上的sessionStorage不为空时,当跟随具有target =“_blank”的链接时,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到HTML5 sessionStorage在下载Weblink时的不同行为。有时,第一页的sessionStorage被复制到TargetPage,有时我在TargetPage上得到一个空的sessionStorage。



任何人都可以解释我为什么会这样?



提供以下连结:

 < a href = TargetPage.htmltarget =_ blank> link< / a> 

当我用右键点击 - >在新标签页中打开链接打开链接时, sessionStorage在TargetPage上为空。 (预期)
但是当我用正常的左键单击打开链接时,sessionStorage会被复制到TargetPage。 (意外)



请注意:我在Chrome和Firefox中看到此行为。 Internet Explorer 9在这两种情况下都提供了一个空的sessionStorage。这是我的预期行为。



我创建了一个jsFiddle来演示行为: http://jsfiddle.net/P9nUv/3/



任何人都可以想到一个跨浏览器解决方案,以确保一个空的sessionStorage新的浏览器标签/ Windows,无论它们是如何打开的?



任何帮助都是非常感激的。

解决方案

IMHO:



我认为问题是在不同的浏览上下文。在W3C webStorage 规范中是一个段落:


当在浏览上下文中创建一个具有
顶级浏览上下文的新文档时,用户代理必须检查
顶级浏览上下文是否具有该
文档的来源的会话存储区




此引用中的

文档表示新页面。
所以这意味着如果你在新标签页中打开相同的页面,它使用相同的浏览上下文和相同的sessionStorage,但如果你在新窗口中打开=_ blank)浏览上下文有所不同。



>

问题可能是单独的CPU线程,因此单独的浏览上下文和单独的 sessionStorage s。


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!

解决方案

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.

这篇关于在新窗口上的sessionStorage不为空时,当跟随具有target =“_blank”的链接时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆