I have a form in my page. I want a confirm close when someone closes the browser. If user clicks the OK button, the form should be submitted and browser should be closed. And if the user clicks the cancel button/close the confirm box, nothing should happen. Here is my code:
<!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>
But the dilemma is that , i am getting my browser closed on click of cancel button/ closing the confirm box as well. Please help.