Question

I've run into an interesting issue and I'm not sure how to solve it. I maintain a hidden value on my homepage that tracks the events loaded on the page. The event position gets updated after the page loads. When navigating away from the page and then clicking the browsers back button the previous event number is seen. If I click a link and load the home page directly the event position gets reset (as expected)

My HTML:

    <input type="hidden" id="event_num" value="0">

My javascript call to get/set the event_num value:

 function getRecentEvents() {

    var event_pos = $('#event_num').val();
    //console.log("POS: " + event_pos);

    $.getJSON("functions/get_events.php", { f: 'get_events', event_pos: event_pos, limit: limit}, function(data) {

        if (data.events.length > 0) {

            // set the new value        
            $('#event_num').val(data.events_pos);
        }
});

I would expect the hidden field to be 0 every time the page is loaded regardless if the user clicked a link or hit the back button on the browser.

Any idea how I might fix this or is this a known issue?

Was it helpful?

Solution

The page is not loaded again if you click the "back" button, the cached page content is shown. That is, the page as the state of it was the last time you visited it. You could reset the event_num counter on $(document).ready or on a document unload event, then you will get the expected behaviour.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top