chrome 用户定义的 window 值是否保留在页面 refresh/URL 更改中

Are chrome user defined window values retained on page refresh/URL change

在问题中,接受的答案说存储在window中的数据被保留。

它说,

The major difference is that this information is retained across not only page refreshes but also different domains. However, it is restricted to the current tab you're in.

当我尝试从 chrome 开发控制台写入 window 对象并导航到同一域中的其他页面时,值没有保留。

这是我所做的:

  1. 打开https://whosebug.com/unanswered
  2. 打开开发控制台并设置window.testKey = "test-value"
  3. 通过单击问题之一导航到不同的页面 link。
  4. 正在控制台中输入 window.testKey returns 未定义

此外,在 window 上设置一个值然后刷新页面的简单情况似乎也不会保留该值。

我错过了什么?

您引用的部分:

The major difference is that this information is retained across not only page refreshes but also different domains. However, it is restricted to the current tab you're in.

仅约 window.name,这是一个特殊的 属性,并且在某种程度上,这在当前的浏览器中仍然有效。

Window.name:

Modern browsers will reset Window.name to an empty string if a tab loads a page from a different domain, and restore the name if the original page is reloaded (e.g. by selecting the "back" button). This prevents an untrusted page from accessing any information that the previous page might have stored in the property (potentially the new page might also modify such data, which might then be read by the original page if it was reloaded).

我认为这只是一个 hack,您不应该依赖它的功能。对于同一个域,您有 localStoragesessionStorage