Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a JavaScript Function when Back Button of Browser is Clicked [duplicate]

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 solutions but none of them worked for me. Can anybody show me some example code?

like image 452
Hamid Mohayeji Avatar asked Dec 27 '22 15:12

Hamid Mohayeji


1 Answers

In jQuery try this :

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

In javascript :

window.onbeforeunload = function () {
   // put your code here
}
like image 169
senthilbp Avatar answered Dec 29 '22 08:12

senthilbp