Skip to content Skip to sidebar Skip to footer

Call A JavaScript Function When Back Button Of Browser Is Clicked

Possible Duplicate: Best way to detect when user leaves a web page How can I call a javascript or jQuery function when back button of browser is clicked? I have seen some soluti

Solution 1:

In jQuery try this :

$(window).unload( function () 
{
// put your code here
});

In javascript :

window.onbeforeunload = function () {
   // put your code here
}

Solution 2:

<body onUnload="yourFunction();>
<!-- ... -->
</body>

Solution 3:

You can use history.replaceState() (see browser support) to modify the previous URL you visited to the current page with an added parameter of your choosing like for instance redirect=<URL of previous actual previous page> (you can maybe get this URL from the referer?), then detect the parameter in document ready and perform the required actions.

This is just an untested theory, I might elaborate later on when I get to test it.


Post a Comment for "Call A JavaScript Function When Back Button Of Browser Is Clicked"