0

I am sure others have encountered this problem before, but this is doing my head in.

I have a page that generates a list of products. It's a long list so may go over several pages. I have Back and Next buttons to achieve this and they work if the user stays with the list.

The problem occurs when the user selects a product from the list and navigates away to a new page to display more details on the product. When the user has finished with this page and exits, the list of products is redisplayed at the point at which the user left it.

In chrome, the popstate is fired, and I have to adjust the number of go-backs required (due to pushStates I have already performed) on the next popstate in order to get the back button to then go to the correct previous page. In firefox, the page is being restored from the cache, and I am not being given the chance to intercept the return and make the necessary adjustments.

Is there some way to force Firefox to clear the cache and trigger the popstate when the back button or exit button is selected from the product detail page?

user3279063
  • 35
  • 1
  • 3

2 Answers2

0

I've used this jQuery code before, and it works cross-platform:

$(window).bind('popstate', jQuery.proxy(function() {
    // your code here
}, this));

The code inside the callback will run anytime the user presses the back button.

It's unlikely to be easy to force Firefox to clear its cache for security reasons. Here's one tip I found that might work (untested by me). But hopefully you can use this callback to do something else that's useful, like setting your navigation state correctly.

You might be able to find more useful information here.

Community
  • 1
  • 1
Jonathan Benn
  • 2,908
  • 4
  • 24
  • 28
0

I think you need a window.onunload handler. See https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching which talks about the introduction of bfcache.

Sean Hogan
  • 2,902
  • 24
  • 22