Reputation: 622
I am working on a legacy webpage that the layout breaks in Chrome only when a user refreshes. So, I noticed that if I hold down shift+refresh it load the UI correctly the next time the user refreshes. This is a quick bug that do not want to spend too much time on. This is what I have so far:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if( is_chrome && document.refresh.visited.value == "" ){
document.refresh.visited.value = "1";
}
else{
location.reload(true);
}
I also have a hidden input with a value="" at the top of the page. I just want to be able to do a hard refresh every time they come to this page the second time and every time thereafter.
Upvotes: 0
Views: 137
Reputation: 480
Try adding this function:
function getParameter(paramName) {
var searchString = window.location.search.substring(1),
i, val, params = searchString.split("&");
for (i=0;i<params.length;i++) {
val = params[i].split("=");
if (val[0] == paramName) {
return unescape(val[1]);
}
}
return null;
}
and then use:
window.location = 'yourPage.html?reloadMe=true';
So your code would be:
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
var reload = true;
if(getParameter("reloadMe")=="true"){
reload = false;
}
if( is_chrome && reload){
window.location = 'yourPage.html?reloadMe=true';
}
I don't know if this will help with your cache issue but it will stop page from reloading over and over again.
Upvotes: 1