Hello, I am working on nextJs project, there is a unique requirement when the user goes to close the browser tab that time needs to open some other popup, but there is one problem when I click on to tab close button first default shows me this alert then I click to cancel then its show my popup, the requirement is open only my popup(i don't want change alert box message, just need to off alert box.), please help me if anyone knows solution Thank you.
My Popup is not an alert box, its an HTML and CSS.
const [openPopUp, setOpenPopUp] = useState(false);
const onBackButtonEvent = (e) => {
e.preventDefault();
setOpenPopUp(true)
e.returnValue = "";
return ""
}
useEffect(() => {
window.history.pushState(null, null, window.location.pathname);
window.addEventListener('popstate', onBackButtonEvent);
window.addEventListener('beforeunload', onBackButtonEvent);
window.alert = function() { };
return () => {
window.removeEventListener('popstate', onBackButtonEvent);
window.removeEventListener('beforeunload', onBackButtonEvent);
};
}, []);