Reputation: 11
window.location.reload()
when called on load its reloading page everytime I want to reload page once whenever the browser's back button is clicked
Upvotes: 1
Views: 4670
Reputation: 7289
function SetCookie (name, value) {
var argv=SetCookie.arguments;
var argc=SetCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=name+"="+escape(value)+
((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
if (getCookie('first_load'))
{
if (getCookie('first_load')==true)
{
window.location.reload(true); // force refresh page-liste
SetCookie("first_load",false);
}
}
SetCookie("first_load",true);
Upvotes: 0
Reputation: 51181
Logical. You load the page, which automatically gets reloaded, thus creating a new entry in the history. Now when you go back, you land on the page with window.location.reload()
and the same happens again.
now the question: why are you doing this? I see no reason for window.location.reload()
on pageload.
Upvotes: 0
Reputation: 4368
You could use:
if(history.length) {
window.location.reload();
}
A much better option though if your page must not be cached, would be to set the appropriate cache-control and expires headers, examples of which can be found at http://www.web-caching.com/mnot_tutorial/how.html
Upvotes: 2