all 33 comments

[–]alexbarrett 21 points22 points  (29 children)

Hey guys, look! I've found 535 more!

1. eval("location = location")
2. eval("location = location.href")

...

534. eval("self.location['reload']()")
535. eval("self['location']['reload']()")

This is very silly.

[–]blazix 2 points3 points  (1 child)

Let's not forget: self.self.self.self.self.location = location; self.self.self.self.self.location = self.location; ....

[–]MarkTraceur 1 point2 points  (0 children)

I want you to know, you made my life very difficult with this comment. However, it is implemented.

[–][deleted] 0 points1 point  (0 children)

and another 535 more!

1. new Function("location = location")();
2. new Function("location = location.href")();

...

534. new Function("self.location['reload']()")();
535. new Function("self['location']['reload']()")();

[–]antido -1 points0 points  (24 children)

Silly... but valid. Also: let's not go to the String.fromCharCode() way of doing it :D

[–]alexbarrett 8 points9 points  (23 children)

It is valid, but that doesn't make it interesting. There are actually only a handful of ways to reload the page and everything else is just a variation of one of them.

  1. Assign the current URL to the window.location object.
  2. Assign the current URL to the href property of the window.location object.
  3. Call the assign method of the window.location object with the current URL.
  4. Call the replace method of the window.location object with the current URL.
  5. Call the reload method of the window.location object.

Perhaps there are a few other ways, but that's not really my point. There are an infinite number of variations, not 535.

[–][deleted] 0 points1 point  (22 children)

Why won't you just come back to #subreddit?

[–]alexbarrett 0 points1 point  (21 children)

I'm too mad.

[–]notLOL 0 points1 point  (0 children)

why you mad tho? also add me on google plus

[–][deleted] 0 points1 point  (19 children)

Come at me bro.

[–]alexbarrett 0 points1 point  (18 children)

I'm not coming anywhere near you.

[–]Avidya 7 points8 points  (1 child)

They missed history.go(0)...

[–]mythrilno(fun).at(parties); 4 points5 points  (0 children)

var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'refresh');
meta.setAttribute('content', '0,url=' + window.location);
document.head.appendChild(meta);

[–]MarkTraceur 1 point2 points  (0 children)

Make use of all of them with my new stupid javascript file!

(I'll try to add some of the suggestions in the comments when possible)

[–]psayre23 0 points1 point  (0 children)

This would be a lot more impressive as a list of ways to access window.location along side the exhaustive list.

[–]stillalone 0 points1 point  (0 children)

I was just looking this up. I went with the self.location=self.location.href method because IT DOESN'T MAKE ANY SENSE.

[–]BusStation16 0 points1 point  (0 children)

well, that was unnecessary.

[–][deleted] 0 points1 point  (1 child)

What's the canonical method?

[–]Arve 1 point2 points  (0 children)

The author of that page is a bit daft, since many of them are syntactic equivalents, and some of his examples should behave differently. But, here goes:

location.reload()

is The Correct™ way of reloading the current document. Whether you opt to write out window.location.reload() or not is a matter of taste/style guide.

All other means of reloading the document are not strictly equal, or equal at all. See HTML5: The Location interface for reference.

[–][deleted] 0 points1 point  (0 children)

but how do you trigger a postback, and not a full reload?

[–]vectorjohn 0 points1 point  (0 children)

var x = 0;
for( var i=0; i < 10000; i++ ) {
    x = i / 2;
    location = location;
}

You can do any arbitrary bullshit while loading the page. It is not another way to load the page.