Javascript 浏览器确认关闭:取消按钮也会关闭浏览器
我的页面中有一个表单。当有人关闭浏览器时,我需要确认关闭。如果用户单击“确定”按钮,则应提交表单并关闭浏览器。如果用户单击取消按钮/关闭确认框,则不会发生任何事情。这是我的密码:Javascript 浏览器确认关闭:取消按钮也会关闭浏览器,javascript,html,confirm,Javascript,Html,Confirm,我的页面中有一个表单。当有人关闭浏览器时,我需要确认关闭。如果用户单击“确定”按钮,则应提交表单并关闭浏览器。如果用户单击取消按钮/关闭确认框,则不会发生任何事情。这是我的密码: <!DOCTYPE html> <html> <script language="JavaScript"> function closeEditorWarning(){ if(confirm('Are you sure want to close this window')) { d
<!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>
函数closeEditorWarning(){
如果(确认('您确定要关闭此窗口'))
{
document.quick.submit();
}
}
window.onbeforeunload=closeEditorWarning;
名字:
姓氏:
单击提交按钮,输入将打开“hello.html”
但两难的是,我要在点击取消按钮/关闭确认框时关闭浏览器。请帮助。您无法通过comfirm()控制关闭事件 但您可以在离开此页之前按事件进行确认
function closeEditorWarning(e){
e = e || window.event;
e.returnValue = 'Are you sure want to close this window?';
}
看看这些:还有