I want to know how i can ensure page reload/refresh when user presses the back button and then presses forward again.? Please help!
Asked
Active
Viewed 788 times
1
-
Possible [duplicate](http://stackoverflow.com/questions/9071838/force-reload-refresh-when-pressing-the-back-button) – Erik Dec 16 '14 at 08:54
2 Answers
0
You can use cookie to set "back button pressed" flag.
eg. jQuery + jquery cookie plugin
$(document).ready(function($) {
if ($.cookie("reload") === *YOUR-PAGE-ID*) {
$.removeCookie("reload");
location.reload();
} else if (window.history && window.history.pushState) {
window.history.pushState("forward", null, "./#forward");
$(window).on("popstate", function() {
$.cookie("reload", *YOUR-PAGE-ID*); // set cookie with some page id
});
}
});
Since popstate
is not supported by older browsers you should use history.js

Marek Ka.
- 327
- 3
- 14
-1
<input type='button' onclick="window.location=window.location.href;">
demo is at my website http://vitideas.in/stackoverflow/

Saurabh Saluja
- 190
- 1
- 9
-
This will only refresh current page on button clik. You need to store 'navigation back' state. – Marek Ka. Dec 16 '14 at 09:22
-
Okay.I didn't get you.you want to track whether the user has refreshed a page?. – Saurabh Saluja Dec 16 '14 at 09:27