[英]confirmation before exit dialog
In most pages, if your doing an action, (like editing, creating), and when I attempt to exit, it mostly prompts me if I really want to exit. 在大多数页面中,如果你正在做一个动作(比如编辑,创建),当我试图退出时,它会提示我是否真的要退出。 The dialog gives me two options: leave or cancel and continue.
该对话框提供了两个选项:离开或取消并继续。 How do you accomplish this in JavaScript?
你是如何在JavaScript中实现这一目标的? Do I have to use a meta element?
我必须使用元元素吗?
And please don't mention
beforeunload
, unless it's the true and only way to accomplish this.
请不要提及
beforeunload
,除非这是实现这一目标的唯一方法。
Why not mention onbeforeunload
? 为什么不提一下
onbeforeunload
? It's the built in way to do so, and I don't see a problem using it. 这是内置的方式,我没有看到使用它的问题。
function myConfirmation() {
return 'Are you sure you want to quit?';
}
window.onbeforeunload = myConfirmation;
我用的是:
onClick="return confirm('Sure you want to exit..?')"
window.onbeforeunload = function() {
if(confirm('are you sure to exit?'))
return true;
else
return false;
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.