我的页面中有一个表格。当有人关闭浏览器时,我想要确认关闭。如果用户单击“确定”按钮,则应提交表单并关闭浏览器。如果用户单击取消按钮/关闭确认框,则不会发生任何事情。这是我的代码:
<!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>
但困境是,我在单击取消按钮/关闭确认框时关闭浏览器。请帮忙。