선생님 안녕하세요
웹에서 뒤로가기 시에 이벤트 감지해서 나갈꺼냐고 물어보고 싶은데 방법이 있을까요?
구글링해서 아래와 같이 했는데 다른 환경(안드로이드,데스크탑 등)에서는 작동을 하는데 아이폰 사파리에서는 안먹혀서.. 헤매고 있습니다. 도와주세요 ㅠㅠ
useEffect(() => {
const preventGoBack = () => {
if (confirm('페이지를 나가시겠습니까?')) {
history.go(-1);
} else {
history.pushState(null, '', location.href);
}
};
history.pushState(null, '', location.href);
window.addEventListener('popstate', preventGoBack);
return () => window.removeEventListener('popstate', preventGoBack);
}, []);