Force Refresh/reload When User Navigates Back And Forward Again
I want to know how i can ensure page reload/refresh when user presses the back button and then presses forward again.? Please help!
Solution 1:
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();
} elseif (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
Solution 2:
<inputtype='button' onclick="window.location=window.location.href;">
demo is at my website http://vitideas.in/stackoverflow/
Post a Comment for "Force Refresh/reload When User Navigates Back And Forward Again"