私のページにフォームがあります。誰かがブラウザを閉じたときに閉じることを確認したい。ユーザーが [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>
しかし、ジレンマは、キャンセルボタンをクリックしたり、確認ボックスを閉じたりすると、ブラウザが閉じられることです。助けてください。