자기 혐오 개발자
Session이 끊겼을때, 팝업을 띄우니 로그인창이 나오면.. 본문
팝업을 띄웠는데, session이 끊겨서 로그인 창이 나오는 홈페이지가 종종 보인다.
내가 만든 사이트에서도 이런 일이 생겨서 우짜꼬 하다가
로그인 창에서 이 창이 부모창인지 자식창인지 구분해가, 어떤 조치를 취하면 되지않을까 해서 구분하는 코드를 찾아봤다.
Google하니 나오더라.
http://stackoverflow.com/questions/4594492/to-check-parent-window-is-iframe-or-not
우선 두 개를 찾았다.
if(self==top){
alert('self==top');
}else if(parent==top){
alert('parent==top');
}
'self==top' 는 팝업이 아닌, 일반창에서 열린 경우고,
'parent==top는 팝업이다.
var isInIFrame = (window.location != window.parent.location);
if (isInIFrame==true) {
}
이 코드는 iFrame에서 열린 경우. 자주 쓰는 Modal팝업에서 쓰면 된다.
내가 구현한 코드.
var isInIFrame = (window.location != window.parent.location);
if (isInIFrame==true) {
parent.window.document.location.href = "로그인URL";
parent.window.parent.closeModal(); // 팝업을 닫는다.
}
'Javascript,jQuery' 카테고리의 다른 글
img 태그 안에 default 이미지 설정하는 방법. (0) | 2018.06.20 |
---|---|
toggle이 열렸는가 안열렸는가 감지하는 방법. (0) | 2018.06.04 |
[jQuery] 드래그해서 정렬, 순서조정 (0) | 2018.05.28 |
html 라디오 버튼 제어 (0) | 2018.05.25 |
INPUT 박스에서 숫자만 입력 되도록 설정 (0) | 2016.10.31 |