1

I want to know how i can ensure page reload/refresh when user presses the back button and then presses forward again.? Please help!

Prashant
  • 105
  • 1
  • 2
  • 8
  • Possible [duplicate](http://stackoverflow.com/questions/9071838/force-reload-refresh-when-pressing-the-back-button) – Erik Dec 16 '14 at 08:54

2 Answers2

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