Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 533
donohoe Avatar asked Aug 10 '11 17:08

donohoe


2 Answers

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
like image 176
Felipe Brahm Avatar answered Sep 21 '22 14:09

Felipe Brahm


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

like image 41
jdzakarian Avatar answered Sep 18 '22 14:09

jdzakarian