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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With