I'm trying to add a function while closing the tab , a pop shows up with leave and cancel, i want to add a function for specific buttons like , if i click on leave button it should call a one function and if i click on cancel button it should call other function. please help me thanks in advance
window.addEventListener("beforeunload", (ev) => {
ev.preventDefault();
socket.current.emit(
"logout_patient",
history.location.state.data.doctorAlias,
socket.current.id,
history.location.state.data.patientId
);
return ev.returnValue = 'Are you sure you want to close?';
});