2019년 6월 2일 일요일

javascript history back

뒤로 가기 동작 제어 - javascript

** 뒤로 가기 동작을 제어하기 위하여 모든 페이지에서 이벤트를 구성합니다.
** 참고 : https://developer.mozilla.org/ko/docs/Web/API/History_API

var GLOBAL_function_forewordPage = function(){
if ( /MSIE/.test(navigator.useragent) || /rv:1/.test(navigator.useragent) ){
     history.back();
 }else{
     location.href='frog-rammer.blogspot.com';
};
history.pushState(null,null,location.href);
window.onpopstate = function(event){
GLOBAL_function_forewordPage();
}
1. GLOBAL_function_forewordPage
뒤로 가기 동작 시에 넘어 가야 할 페이지를 지정하는 변수 입니다.
자바 스크립트에서는 함수란 하나의 값으로써 변수에 담을 수 있습니다.
이를 이용하여 변수의 함수를 덮어쓰면서 동작을 제어 할 수 있습니다.
예를 들어 특정 페이지에서는 뒤로 가기 동작 시 특정 함수를 호출해야 한다면
해당 변수의 값을 특정 함수로 덮어쓰면 됩니다.
2. history.pushState( state 객체, title, [option] URL )
옵션인 URL 부분에 현재 페이지를 등록하여 새로운 히스토리 등록
3. window.onpopstate
뒤로 가기 동작 시의 이벤트