开发者

535 Ways to Reload the page with JavaScript - what are the consequences?

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
locatio开发者_如何学Cn = 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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜