0

Using Javascript, I'm trying to reload my page and add a parameter before doing so. I've added the alerts to debug why the parameter is not getting passed to the server:

    alert('before: ' + window.location.href);
    window.location.href = window.location.href + "?advanced_expand=true";
    alert('after: ' + window.location.href);
    window.location.reload();

What has me perplexed is that the first alert is:

before: http://localhost:3000/orgconf/quick_org_benefit/edit/784

and the second is:

after: http://localhost:3000/orgconf/quick_org_benefit/edit/784

without the parameter added...what gives?

Mark Kadlec
  • 7,096
  • 15
  • 58
  • 93
  • possible duplicate of [Adding a parameter to the URL with JavaScript](http://stackoverflow.com/questions/486896/adding-a-parameter-to-the-url-with-javascript) – matewka Feb 25 '15 at 15:47

1 Answers1

2

Doing the window.location.reload() afterwards is pointless because setting window.location.href changes the page. Likewise, window.location.href doesn't actually change until the page changes. That's why you aren't seeing the URL change.

If the page is reloading and it still hasn't changed, make sure your URL rewriting isn't removing GET parameters that come after a ?.

Mike Cluck
  • 28,921
  • 12
  • 72
  • 85