title: Reload browser window after POST without prompting user to resend POST data
body: <p>When a user visits my website there is a "Login" link on every page. Clicking this uses some JavaScript to show an overlay window where the user is prompted for their credentials. After entering these credentials an Ajax call is made to the web server to validate them; if they are valid, an authentication ticket cookie is sent back and the page is reloaded so that any content on the page that is specific to authenticated users or the (now) currently logged in user is displayed.</p>
  
  <p>I am accomplishing the page reload via script using:</p>
  
  <pre><code>window.location.reload();
  </code></pre>
  
  <p>This works wonderfully for pages loaded via a GET request (the vast majority), but some pages use postback forms. So if a user goes to one of these pages, performs a postback, and then chooses to login, when the <code>window.location.reload()</code> script runs they are prompted with the dialog box asking if they want to resubmit the POST body.</p>
  
  <p><img src="https://i.stack.imgur.com/oNALr.png" alt="Resubmit POST body dialog box"></p>
  
  <p>I thought to get around this I could just tell the browser to reload the page, so I tried:</p>
  
  <pre><code>window.location.href = window.location.href;
  </code></pre>
  
  <p>But the browser doesn't take any action with the above statement, I presume because it's thinking the new URL is the same as the old. If I change the above to:</p>
  
  <pre><code>window.location.href = window.location.pathname;
  </code></pre>
  
  <p>It reloads the page, but I lose any querystring parameters.</p>
  
  <p>My current workaround is sufficient, but not pretty - in short, I tack on a querystring parameter to the current <code>window.location.href</code> value and then assign that back to <code>window.location.href</code> by calling <code>reloadPage("justLoggedIn")</code>, where the <code>reloadPage</code> function is:</p>
  
  <pre><code>function reloadPage(querystringTackon) {
      var currentUrl = window.location.href;
  
      if (querystringTackon != null &amp;&amp; querystringTackon.length &gt; 0 &amp;&amp; currentUrl.indexOf(querystringTackon) &lt; 0) {
          if (currentUrl.indexOf("?") &lt; 0)
              currentUrl += "?" + querystringTackon;
          else
              currentUrl += "&amp;" + querystringTackon;
      }
  
      window.location.href = currentUrl;
  }
  </code></pre>
  
  <p>This works, but it results in the URL being <code>www.example.com/SomeFolder/SomePage.aspx?justLoggedIn</code>, which seems tacky.</p>
  
  <p>Is there a way in JavaScript to get it to do a GET reload and not prompt the user to resubmit the POST data? I need to make sure that any existing querystring parameters are not lost.</p>