In the question, Persist variables between page loads, the accepted answer says that the data stored in window
are retained.
It says,
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.
When I tried writing to window object from chrome dev console and when navigated to some other page on the same domain, the values weren't retained.
This is what I did:
- Open https://stackoverflow.com/unanswered
- Open dev console and set
window.testKey = "test-value"
- Navigate to a different page by clicking one of the questions link.
- Entering
window.testKey
in console returns undefined.
Also, a simple case of setting a value on window followed by a page refresh also doesn't seem to retain the value.
What am I missing?