为什么window.name被缓存? [英] Why is window.name cached?

查看:97
本文介绍了为什么window.name被缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我最近参与的编程挑战中,我不得不使用 window.name 属性来存储/操作数据。我发现,当你更改这个属性时,它会持续通过页面刷新(虽然不是在打开具有相同URL的新页面时)。

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).

我能做的唯一信息发现这是已知的,甚至被一些框架用作数据存储,但我会感兴趣的原因(因为为什么window.name持久?任何历史原因?)以及如何(当有哪些规则时) window.name 是否在页面更改和丢弃之间保持不变?)。

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?).

显然,我的Google-fu不足以找到这些问题的答案(在MDN页面上甚至没有提到它!)所以我希望也许你可以帮助我。

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.

推荐答案

我对它的理解是窗口对象在选项卡的整个生命周期中都是持久的,并且表示加载不同HTML文档的窗口。

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.

每个标签都包含自己的窗口对象,这就是为什么即使你导航到/从不同的页面窗口对象是持久性的,而如果你在另一个标签上检查 window.name 将是不同的。

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.

打开时不同的html页面,大多数不会覆盖 window.name 属性,它是完全可选的。如果没有别的东西在操纵它,那将是你留下的。大多数页面只涉及操纵 window.document 本身。

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.

这篇关于为什么window.name被缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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