我在window close
事件上显示警告对话框。如果用户点击Cancel
控件停留在同一页面上,或者如果用户点击Okay
,他就会导航到所需的页面。
我想收集对话框的值意味着用户是否点击了Cancel
或Okay
。我在外部javascript中编写了以下代码
$(document).ready(function()
{
window.onbeforeunload = askConfirm;
function askConfirm()
{
if (flag)
{
// Message to be displayed in Warning.
return "Your unsaved data will be lost.";
}
}
}
我如何收集价值?
答案 0 :(得分:3)
<script type="text/javascript">
window.onbeforeunload = function (evt) {
return "Are you sure to close?";
}
</script>
示例代码
http://files.dropbox.com/u/642364/blogger/scripts/close.html
修改强> 在窗口关闭时从用户那里获取响应代码
<body onUnload = "CheckIt ()" >
...
</body>
<script>
function CheckIt ()
{
var response = confirm ("Are you closing..");
alert (response); // do whatever for response.
}
</script>