Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch "History.Back" event in javascript?

is it posible to catch "History.Back" event in javascript? İ want to catch history.back() event and logout user.

P.s : There is some code about disabling history.back(). But is not useful for me.

<script type = "text/javascript" >
 function disableBackButton()
 {
   window.history.forward();
 }
 setTimeout("disableBackButton()", 0);
</script>

then set onunload event

<body onunload="disableBackButton()">
like image 650
maycil Avatar asked Feb 11 '11 09:02

maycil


People also ask

What is JavaScript history back ()?

back() The History. back() method causes the browser to move back one page in the session history. It has the same effect as calling history.go(-1) .

Can I use history back ()?

back() is the same as history.go(-1) . history. back() is the same as clicking "Back" your browser.

What is the syntax and use of history back () method?

The History back() method in HTML is used to load the previous URL in the history list. It has the same practical application as the back button in our web browsers. This method will not work if the previous page does not exist. This method does not contain any parameter.

How do I go back to previous page in JavaScript?

back() method: The back() method of the window. history object is used to go back to the previous page in the current session history.


1 Answers

You can catch history back using "window.onpopstate" event. But AFAIK it is only available in HTML5.

http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-definitions-0

like image 53
gox Avatar answered Oct 25 '22 20:10

gox