1

私のページにフォームがあります。誰かがブラウザを閉じたときに閉じることを確認したい。ユーザーが [OK] ボタンをクリックすると、フォームが送信され、ブラウザーが閉じられる必要があります。また、ユーザーがキャンセル ボタンをクリックしたり、確認ボックスを閉じたりしても、何も起こりません。これが私のコードです:

<!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>

しかし、ジレンマは、キャンセルボタンをクリックしたり、確認ボックスを閉じたりすると、ブラウザが閉じられることです。助けてください。

4

1 に答える 1

0

comfirm() による終了イベントの制御はできません。

イベントでこのページを離れる前に確認できます。

function closeEditorWarning(e){
    e = e || window.event;
    e.returnValue = 'Are you sure want to close this window?';
}
于 2013-11-24T05:20:54.800 に答える