使用 JavaScript 重新加载页面的 535 种方法 - 后果是什么?

发布于 2024-11-28 16:08:14 字数 1226 浏览 0 评论 0原文

有人列出了 535 种在 Javascript 中重新加载页面的不同方法:

http:// www.phpied.com/files/location-location/location-location.html

例如:

location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
location = window['location'].href
location = window['location']['href']
location = window.location['href']
location = self['location']
location = self['location'].href
location = self['location']['href']
location = self.location['href']
location.assign(location)
location.replace(location)
window.location.assign(location)
window.location.replace(location)
self.location.assign(location)
self.location.replace(location)
location['assign'](location)
window.location['assign'](location)
self['location'].assign(location)
self['location']['assign'](location)
self['location']['replace'](location)
location.href = location
location.href = self.location
location.href = window.location.href

我很好奇是否有人知道这些在浏览器上的处理方式不同 - 是否刷新页面但破坏缓存 - 或者不是视情况而定吗?

Someone has listed 535 different ways to reload a page in Javascript:

http://www.phpied.com/files/location-location/location-location.html

For example:

location = location
location = location.href
location = window.location
location = self.location
location = window.location.href
location = self.location.href
location = location['href']
location = window['location']
location = window['location'].href
location = window['location']['href']
location = window.location['href']
location = self['location']
location = self['location'].href
location = self['location']['href']
location = self.location['href']
location.assign(location)
location.replace(location)
window.location.assign(location)
window.location.replace(location)
self.location.assign(location)
self.location.replace(location)
location['assign'](location)
window.location['assign'](location)
self['location'].assign(location)
self['location']['assign'](location)
self['location']['replace'](location)
location.href = location
location.href = self.location
location.href = window.location.href

I'm curious if anyone knows how these are treated differently on the browser - whether one refreshes the page but busts cache - or not as the case may be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素染倾城色 2024-12-05 16:08:14

浏览器对所有这些示例的处理方式相同。

事实上,它们中的大多数只是在 Javascript 中访问变量的不同方式。您可能可以编写一个类似的列表,其中包含“XXX 为全局变量分配另一个全局变量的值的不同方法”。

例如:location.href、window.location.href、self.location.href、location['href']、window.location['href']、self.location['href']都指向完全相同的值。

在您发布的列表中,唯一两种真正不同的方式是这些

location = location //assign the whole location object to the location global variable
location = location.href //assign the string location.href to the location global variable

All those examples are treated the same by the browser.

In fact, most of them are just different ways of accessing a variable in Javascript. You could probably write a similar list with "XXX different ways of assigning a global variable the value of another global variable".

For example: location.href, window.location.href, self.location.href, location['href'], window.location['href'], self.location['href'] are all pointing to the exact same value.

In the list you posted, the only two really different ways are these:

location = location //assign the whole location object to the location global variable
location = location.href //assign the string location.href to the location global variable
猥︴琐丶欲为 2024-12-05 16:08:14

location.reload() 的作用类似于表单提交(即传递所有表单值)

location.reload() acts like a form submit (i.e. it passes all the form values)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文