使用 JavaScript 重新加载页面的 535 种方法 - 后果是什么?
有人列出了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器对所有这些示例的处理方式相同。
事实上,它们中的大多数只是在 Javascript 中访问变量的不同方式。您可能可以编写一个类似的列表,其中包含“XXX 为全局变量分配另一个全局变量的值的不同方法”。
例如:location.href、window.location.href、self.location.href、location['href']、window.location['href']、self.location['href']都指向完全相同的值。
在您发布的列表中,唯一两种真正不同的方式是这些:
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.reload()
的作用类似于表单提交(即传递所有表单值)location.reload()
acts like a form submit (i.e. it passes all the form values)