Can we detect browser update events and back buttons?

Does anyone know how to detect browser updates and return button events in firefox using jquery or javascript.

+4
source share
3 answers

For the back button:

window.addEventListener('popstate', function (event) {
//Your code here
});

To update:

window.onbeforeunload = function () {
 // Your code here
}
+2
source

You can try WindowEventHandlers.onbeforeunload :

window.onbeforeunload = function(e) {

};

and

$(window).unload(function() {
      //
});

Also check Browser Button Detection :

javascript, -, , . - javascript alert " " ".

, OnBack . , .

<script type="text/javascript">
bajb_backdetect.OnBack = function()
{
alert('You clicked it!');
}
</script>

"Back Button Clicked" "You !".

+2

Check out this page: Manipulating your browsing history

Perhaps you can get something that works using history.pushStateandwindow.onpopstate

+1
source

Source: https://habr.com/ru/post/1623869/


All Articles