web/JavaScript
뒤로가기 방지
남기루
2021. 10. 27. 16:35
반응형
보안상 사용자와 client의 상호작용이 없으면 적용되지 않음
function noBack() {
history.pushState('preventLocation', document.title, '#');
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('popstate', clearHistory);
} else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('popstate', clearHistory);
} else {
window.onpopstate = clearHistory;
}
};
function clearHistory() {
history.pushState('popstateFunction', document.title, '#');
};
반응형