Skip to content Skip to sidebar Skip to footer

Triggering A Script (js Or Jquery) Using Browser's "back" Function

I can't find a way to execute a script when a page is reached via the browser's BACK button or key command. (Background: I need to know if a page was opened using the browser's BAC

Solution 1:

after reading lots of posts and trying the solutions in there and narrowing the thing down to a browser issue, I discovered this answer, which forces the page to be reloaded also in Safari (and apparently also Firefox/Mac):

https://stackoverflow.com/a/13123626/5641669

Essentially, this jQuery code reloads the page in its original state when coming there via the back button on Safari, which also allows to trigger any desired script on pageload:

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
        window.location.reload() 
    }
});

Post a Comment for "Triggering A Script (js Or Jquery) Using Browser's "back" Function"