JavaScript/문법

[JS] 팝업창 닫을 때 이벤트 잡기 ( onbeforeunload - 페이지를 벗어날 때)

민돌v 2021. 10. 18. 12:21
728x90

팝업창 닫을 때, 현재 페이지 새로고침을 하기위해, onbeforeunload 이벤트를 사용했다.

onveforeunload 이벤트란,

사용자의 페이지에서 벗어날 때, 즉 뒤로가기나 팝업창을 닫을 때 일어나는 이벤트인 것 같다.

function create_baby_profile() {
    var popup = window.open('/profile/create', '네이버팝업', 'width=700px,height=700px,scrollbars=yes');
    popup.onbeforeunload=function (){
        window.location.reload();
    }
}

 

 

*참고

https://jaimemin.tistory.com/1539

https://doolyit.tistory.com/205

 

반응형