In the standard Java / SpringMVC / JSP / jQuery web application, I try to detect the "Back" event (or history.go (-1)) in order to update (AJAX) the resulting component / when I return to the page (where we can change the backend data which are displayed by the resulting component).
I tried the following in JavaScript (following some posts on StackExchange how to do this):
<script type="text/javascript"> $(document).ready(function() { window.onpageshow = function(event) { console.log("Event:"); console.dir(event); if (event.persisted) { alert("non-jQuery - back to page - loaded from bfcache"); } else { alert("non-jQuery - loaded page from server"); } }; $(window).on("pageshow", function(event){ console.log("Event:"); console.dir(event); if (event.originalEvent.persisted) { alert("jquery - back to page - loaded from bfcache"); } else { alert("jquery - loaded page from server"); } }); }); </script>
I run OpenSUSE Linux and tried this with FireFox and Chrome (latest versions), but every time the event persisted attribute is false (I see this in the JavaScript console and the warnings that pop-up from the code above). Each time, I mean, regardless of whether it was downloaded from the server or shown again using the "Back" (or "Back") button.
My intention was to call an AJAX to reload the resulting component / panel with the updated data from the server, if the page was displayed using the "Back" or "<23" button.
I also tried installing a upload handler (which does nothing) to prevent the page from being placed in bfcache, but it still seems to show the bf caching version and set event.persisted (or event.originalEvent.persisted ) to false
Is this property managed correctly by Linux? Am I doing something stupid in my code? Any help or ideas would be greatly appreciated, thanks!
javascript back-button pageshow
Eoin
source share