2013-09-22 3 views
1

내 페이지에 양식이 있습니다. 누군가가 브라우저를 닫을 때 확인을 원합니다. 사용자가 확인 버튼을 클릭하면 양식을 제출하고 브라우저를 닫아야합니다. 사용자가 취소 버튼을 클릭하거나 확인 상자를 닫으면 아무 일도 일어나지 않습니다. 여기 내 코드입니다 :브라우저 확인 닫기 : 취소 버튼 또한 브라우저를 닫습니다.

<!DOCTYPE html> 
<html> 
<script language="JavaScript"> 
function closeEditorWarning(){ 
if(confirm('Are you sure want to close this window')) 
{ 
document.quiz.submit(); 
} 
} 
window.onbeforeunload = closeEditorWarning; 
</script> 
<form name="quiz" action="Hello.html" method="get" target="_blank"> 
    First name: <input type="text" name="fname"><br> 
    Last name: <input type="text" name="lname"><br> 
    <input type="submit" value="Submit"> 
</form> 
<p>Click on the submit button, and the input will be open "hello.html".</p> 
</body> 
</html> 

그러나 딜레마는, 내가/내 브라우저가 취소 버튼의 클릭에 폐쇄 점점뿐만 아니라 확인 상자를 닫지하고 있다는 점이다. 도와주세요.

+0

체크 아웃이 : http://stackoverflow.com/questions/6579509/how-to-collect-return-value-of-onbeforeunload 및 http://stackoverflow.com/questions/12132060/confirm- on-window-onbeforeunload – ChicagoRedSox

답변

0

닫기 이벤트는 comfirm()로 제어 할 수 없습니다.

하지만이 페이지를 나가기 전에 확인할 수 있습니다.

function closeEditorWarning(e){ 
    e = e || window.event; 
    e.returnValue = 'Are you sure want to close this window?'; 
}