0

I have a website with filters. I have appended hash whenever any filter is applied. For example i have city, color filter.

URL/#color=red&city=Delhi

Now when someone clicks browser back on such url, it becomes URL/#color=red. The city query string is removed by browser.

The problem is the page doesn't reload itself.

$(window).on('hashchange', function () {
    window.location.reload(true);
});

But this is infinitely loading the page.

Sahil Sharma
  • 3,847
  • 6
  • 48
  • 98

3 Answers3

1

Try history API https://developer.mozilla.org/en-US/docs/Web/API/History_API

e.g.

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "bar.html");
Devendra Bhatte
  • 358
  • 4
  • 18
0

Try turning off caching so that when you go back, the browser will automatically obtain a new page from the server...

More information here...

bastos.sergio
  • 6,684
  • 4
  • 26
  • 36
0

You may not want to hear this, but the HTML you have is not valid and needs to be fixed by converting the anchors # to proper query strings ?. This will allow the browser to go back and reload the page.

You can do this using a find and replace in your HTML editor.

If that's going to cause problems to the way you've implemented your filters, you'll need to update your filtering code. If you post that here we can help fix that.

Hope that helps. :-)

Adam Konieska
  • 2,805
  • 3
  • 14
  • 27