I am trying to bind an event on before leaving a page, but except, when the back button is pressed. This is my code for the event:
window.onbeforeunload = (e) => {
if(something){
// do my custom code
}
};
It works, but it binds and when the back button is pressed. This a normal logic, of course, but I need to find a way to check, is it back button pressed inside onbeforeunload
. Something like this:
if(something && !isBackButton){
// do my custom code
}