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 cred
Use
RefreshForm.submit();
instead of
document.location.reload(true);
I had the same problem as you.
Here's what I did (dynamically generated GET form with action set to location.href, hidden input with fresh value), and it seems to work in all browsers:
var elForm=document.createElement("form");
elForm.setAttribute("method", "get");
elForm.setAttribute("action", window.location.href);
var elInputHidden=document.createElement("input");
elInputHidden.setAttribute("type", "hidden");
elInputHidden.setAttribute("name", "r");
elInputHidden.setAttribute("value", new Date().getTime());
elForm.appendChild(elInputHidden);
if(window.location.href.indexOf("?")>=0)
{
var _arrNameValue;
var strRequestVars=window.location.href.substr(window.location.href.indexOf("?")+1);
var _arrRequestVariablePairs=strRequestVars.split("&");
for(var i=0; i<_arrRequestVariablePairs.length; i++)
{
_arrNameValue=_arrRequestVariablePairs[i].split("=");
elInputHidden=document.createElement("input");
elInputHidden.setAttribute("type", "hidden");
elInputHidden.setAttribute("name", decodeURIComponent(_arrNameValue.shift()));
elInputHidden.setAttribute("value", decodeURIComponent(_arrNameValue.join("=")));
elForm.appendChild(elInputHidden);
}
}
document.body.appendChild(elForm);
elForm.submit();
This worked
<button onclick="window.location.href=window.location.href; return false;">Continue</button>
The reason it doesn't work without the return false;
is that the button click would trigger a form submit. With an explicit return false on it, it doesn't do the form submit and just does the reload of the same page that was a result of a previous POST to that page.
This works too:
window.location.href = window.location.pathname + window.location.search
window.location.href = window.location.href;
Don't ask my why it works..but it does :). Just the way the js engine interprets the logic I suppose.
If you have hashes '#' in your URL, all the solutions here do not work. This is the only solution that worked for me.
var hrefa = window.location.href.split("#")[1];
var hrefb = window.location.href.split("#")[2];
window.location.href = window.location.pathname + window.location.search + '&x=x#' + hrefa + '#' + hrefb;
The URL has to be different for it to reload if you have a hash. The &x=x does that here. Just substitute this for something you can ignore. THis is abit of a hack, unable to find a better solution..
Tested in Firefox.