0

I've seen this question already, but the top answers all suggest window.location.reload. I've just discovered that this will actually do a POST if your page was loaded with a POST.

I reckon I could do window.location.href=window.location.href but that won't work if there's a hashtag in the URL I'm told.

So how can I get the browser to perform a GET on the current page, including query params (with or without the hash)?

Community
  • 1
  • 1
mpen
  • 272,448
  • 266
  • 850
  • 1,236
  • Possible duplicate of [How do I reload a page without a POSTDATA warning in Javascript?](http://stackoverflow.com/questions/570015/how-do-i-reload-a-page-without-a-postdata-warning-in-javascript) – TAGraves Nov 19 '15 at 00:09

2 Answers2

1

You can manually construct your URL:

window.location.href=window.location.origin + window.location.pathname + window.location.hash;
RecycleRobot
  • 801
  • 2
  • 11
  • 19
  • The `+ window.location.hash` causes it to *not* navigate when there is a hash. Without it it works fine though. Thank you! – mpen Nov 19 '15 at 01:15
1
function refresh() {
    window.location.href = window.location.pathname + window.location.search;
};

You don't need the origin (it doesn't work in old IE anyway). You should add .search if you want to keep the query params. Don't add .hash because it won't refresh if there is one.

mpen
  • 272,448
  • 266
  • 850
  • 1,236