forked from AcaMate/AcaMate_Web
34 lines
1.2 KiB
JavaScript
34 lines
1.2 KiB
JavaScript
window.navigationHelper = {
|
|
preventBackNavigation: function() {
|
|
// 현재 상태를 히스토리에 추가
|
|
history.pushState(null, null, location.href);
|
|
|
|
// popstate 이벤트 리스너 추가
|
|
window.addEventListener('popstate', function(event) {
|
|
// 뒤로가기 시도 시 다시 현재 페이지로 이동
|
|
history.pushState(null, null, location.href);
|
|
});
|
|
},
|
|
|
|
allowBackNavigation: function() {
|
|
// popstate 이벤트 리스너 제거
|
|
window.removeEventListener('popstate', this.popstateHandler);
|
|
},
|
|
|
|
// 확인 대화상자와 함께 뒤로가기 막기
|
|
preventBackNavigationWithConfirm: function(message) {
|
|
history.pushState(null, null, location.href);
|
|
|
|
window.addEventListener('popstate', function(event) {
|
|
if (confirm(message || '정말로 페이지를 떠나시겠습니까?')) {
|
|
// 사용자가 확인을 누르면 뒤로가기 허용
|
|
history.back();
|
|
} else {
|
|
// 취소를 누르면 현재 페이지 유지
|
|
history.pushState(null, null, location.href);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|