반응형
[JavaScript] 브라우저에서 뒤로가기 했을때, 자바스크립트 실행하기
 

// javascript
window.onpageshow = function(event){
	if( event.persisted ){
        console.log("BFCache로부터 복원됨");
	}else{
        console.log("새로 열린 페이지");
	}
}

// jquery 
$(window).bind("pageshow", function(event){	
	if( event.originalEvent.persisted ){
        console.log("BFCache로부터 복원됨");
	}else{
        console.log("새로 열린 페이지");
	}
});
반응형
반응형

jQuery - Back button Detect, reload  http://www.vvaves.net/jquery-backDetect/

브라우저에서 뒤로가기 버튼 선택시 페이지를 리로드해주는 쿼리. 

단, 라이브러리를 업로드해야 한다. 

https://github.com/ianrogren/jquery-backDetect

 

ianrogren/jquery-backDetect

jQuery backDetect is a jQuery plugin that is used to determine when a user clicks the back button and fire a callback function. - ianrogren/jquery-backDetect

github.com

backDetect

Determining when a user clicks their browser's back button has never been easier with this jQuery plugin. With a quick easy install and minimal set up work you'll be firing callback functions on back button declarations in no time.

View the Project on GitHubianrogren/jquery-backDetect

Using jQuery-backDetect

Can append to any element or class:

$(window).load(function(){ $('body').backDetect(function(){ // Callback function alert("Look forward to the future, not the past!"); }); });</script>

Click the back button to test.

반응형

+ Recent posts