Hi I have a big table of items to administrate. When I click buttons I use
$.post("update_the_database.php", { mode: 'themode', username: username },
function(result){
window.location.href = window.location.href;
});
This runs "update_the_database.php"
in the background then when it is finished it reloads the page. It goes back to the top of the page though...
I've tried:
window.location.href = window.location.href + '#the_id';
but in all browsers (IE, Firefox, Chrome, Safari) it changes the URL in the address bar but doesn't reload the page.
From here:
Difference between window.location.href=window.location.href and window.location.reload()
"window.location.href=window.location.href will not reload the page if there's an anchor (#) in the URL - You must use window.location.reload() in this case."
So I tried:
window.location.reload(true);
and it reloads the page and scrolls down to the previous spot in Chrome and Safari but not IE and Firefox...
How to force a page to reload if all what was changed in url is hash?
Approach #2:
window.location.hash = "#" + newhash;
window.location.reload(true);
Now it works in Firefox...
BTW if I use window.location.reload(true); in IE it comes up with:
Windows Internet Explorer
To display the webpage again, the web browser needs to
resend the information you've previously submitted.
If you were making a purchase, you should click Cancel to
avoid a duplicate transaction. Otherwise, click Retry to display
the webpage again.
Retry Cancel
You have to press "Retry" otherwise it has an error page that says "Webpage has expired".
To avoid that IE popup I'm currently doing:
window.location.hash = "#<?php echo $id;?>";
if (navigator.appName != 'Microsoft Internet Explorer') {
window.location.reload(true);
}
Though it just puts the hash into the address bar and it doesn't refresh the page even if I go to the address bar and press enter. I have to remove the hash and press enter to reload the page... (then it scrolls to the top)