Reload the site when reached via browsers back button

You should use a hidden input as a refresh indicator, with a value of “no”:

<input type="hidden" id="refresh" value="no">

Now using jQuery, you can check its value:

$(document).ready(function(e) {
    var $input = $('#refresh');

    $input.val() == 'yes' ? location.reload(true) : $input.val('yes');
});

When you click on the back button, the values in hidden fields retain the same value as when you originally left the page.

So the first time you load the page, the input’s value would be “no”. When you return to the page, it’ll be “yes” and your JavaScript code will trigger a refresh.

Leave a Comment