I am displaying a warning dialog box on window close
event. If user clicks on Cancel control stays on same page or if user clicks on Okay he get navigat开发者_如何学Goed to desired page.
$(document).ready(function()
{
window.onbeforeunload = askConfirm;
function askConfirm()
{
if (flag)
{
// Message to be displayed in Warning.
return "Your unsaved data will be lost.";
}
}
}
How can I collect the value?
<script type="text/javascript">
window.onbeforeunload = function (evt) {
return "Are you sure to close?";
}
</script>
example code
http://files.dropbox.com/u/642364/blogger/scripts/close.html
EDIT Getting the response code from the user on window close
<body onUnload = "CheckIt ()" >
...
</body>
<script>
function CheckIt ()
{
var response = confirm ("Are you closing..");
alert (response); // do whatever for response.
}
</script>
精彩评论