Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is window.name cached?

Tags:

javascript

in a programming challenge I recently took part in I had to use the window.name property to store / manipulate data. I found out that, when you change this property, it persists through page refreshes (although not when opening a new page with the same URL).

The only information I could find was that this is known and even used by some frameworks as data storage, but I would be interested in the why (as in why is window.name persistent? Any historical reasons?) and the how (which rules are there of when the window.name is kept between page changes and when it is discarded?).

Apparently, my Google-fu is not strong enough to find the answers to these questions (there is not even a mention of it on the MDN page!) so I hope that maybe you could help me.

like image 674
DHainzl Avatar asked Oct 12 '15 06:10

DHainzl


1 Answers

My understanding of it is that the window object is persistent throughout the lifetime of a tab, and represents the window that is loading different HTML documents.

Each tab contains its own window object, which is why even when you navigate to/from different pages the window object is persistent, whereas if you check on a different tab the window.name will be different.

When opening different html pages, most of them do not override the window.name property, and it is completely optional. If nothing else is manipulating it, it will be what you leave it as. Most pages only touch on manipulating the window.document itself.

like image 169
David Li Avatar answered Nov 23 '22 12:11

David Li