왜 이게 안되죠?
본문
<div class="btn_list01 btn_list" style="margin-top:20px; text-align:center">
<input type="submit" name="act_button" value="선택수정" onclick="document.pressed=this.value(); opener.location.reload(); window.close();">
</div>
서브밋하고 리로드 후 창닫으려하는데 안되네요,,
왜그럴가요?
document.pressed=this.value(); 이게 없으면 클릭후 닫히는데..
함께 있으니 안되거든요,,
답변 2
안될 수 밖에 없죠...
<input type="submit" name="act_button" value="선택수정" onclick="document.pressed=this.value(); opener.location.reload(); window.close();">
의 경우 클릭시
document.pressed=this.value(); 먼저 실행하면서 submit이 걸립니다.
form을 submit 하게 되면 만약 현재 A페이지라고 하면
----> B페이지로 이동하게 되겠죠. 보니깐 게시판 수정페이지 인거 같은데
<form name="fboardlist" id="fboardlist" action="./board_list_update.php" onsubmit="return fboardlist_submit(this);" method="post">
에 의하면 fboardlist_submit(this) 함수가 실행되고 board_list_update.php로 이동합니다.
그러면 그뒤 A페이지에서 B페이지로(./board_list_update.php)로 이동하니깐 A페이지의 자바스크립트
명령어 opener.location.reload(); window.close(); 를 실행하지 못하게 되는 것이죠.
그리고 onclick="document.pressed=this.value(); opener.location.reload(); window.close();">에서
this.value(); 가 아닙니다.(함수콜 아님) this.value; 입니다. 요거도 오류라 말씀 드립니다.
그러면 submit 처리하고 부모창을 새로고침하고 내 창을 닫고 싶다면 방법은 두가지 정도 압축할 수 있겠네요.
1. A 페이지가 새창이라는 걸 알리고 B가 opener.location.reload(); window.close();를 실행하게 하는방법
2. A 페이지가 비동기통신(ajax)로 submit을 처리하고(페이지 변화가 없게하고) 난 뒤 opener.location.reload(); window.close();을 스스로 처리하는 방법.
우선 질문자가 지켜본 봐로는 공부중이신 새싹인거 같아 2방법은 좀 더 공부하시고 시도 해보시고
1방법을 말씀 드리면 우선 A페이지에 다음과 같이 추가 합니다.
<div class="btn_list01 btn_list" style="margin-top:20px; text-align:center">
<input type="hidden" name="sub_page" value="1">
<input type="submit" name="act_button" value="선택수정" onclick="document.pressed=this.value">
</div>
그리고 B페이지 submit을 처리하는 페이지 가셔서 아마(./board_list_update.php)일테죠???
어디서 처리하고 계신지 모르겠지만 여튼 가보시면 제일 하단에
goto_url('./board_list.php?'.$qstr); 이라고 있을 꺼예요. 그 부분을 다음과 같이 처리 해보시길
바랍니다.
if($_POST['sub_page']){
?>
<script>
opener.location.reload();
window.close();
</script>
<?
}else{
goto_url('./board_list.php?'.$qstr);
}
!-->!-->
onclick="document.pressed=this.value(); opener.location.reload(); window.close();"
이러면 다음과 같은 처리가 있어야 겠는데
<script>
if (document.pressed == "선택수정") {
//처리구문
} else { // 처리구문 }
</script>
이런 처리구문이 있나 확인해 보시고
혹시 모르니 자바스크립트 오류나는 부분도 확인해 보시죠.