javascript 是否可以在一段时间后关闭确认框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10416798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is it possible to close confirm box after a time interval?
提问by developer747
I need to display this message to the user where the user can click 'Yes' or 'No'. If the user doesn't respond in 2 minutes, the window needs to closed. Opening a new page is one way. My question is, is it possible to do this with a confirm box? Can a confirm box be automatically closed after 2 minutes?
我需要向用户显示此消息,用户可以在其中单击“是”或“否”。如果用户在 2 分钟内没有响应,则需要关闭窗口。打开新页面是一种方法。我的问题是,是否可以使用确认框来执行此操作?确认框可以在 2 分钟后自动关闭吗?
采纳答案by ThiefMaster
You cannot do that with the native confirm()
as it blocks JavaScript execution on that page until the user has "answered" but there are lots of HTML/JavaScript-based inplementations out there where you could easily add such behaviour.
And they often look better, too. :)
您不能使用本机confirm()
执行此操作,因为它会在用户“回答”之前阻止该页面上的 JavaScript 执行,但有许多基于 HTML/JavaScript 的实现,您可以轻松添加此类行为。
而且它们通常看起来也更好。:)
Have a look at https://stackoverflow.com/a/972832/298479for an example. To create the timeout, you'd simply window.setTimeout(function() { $('#dialog').dialog('close'); }, 120000);
when opening the dialog.
以https://stackoverflow.com/a/972832/298479为例。要创建超时,您只需window.setTimeout(function() { $('#dialog').dialog('close'); }, 120000);
在打开对话框时即可。
回答by Diodeus - James MacFarlane
Alert
and Confirm
boxes cannot be scripted to close. Use a modal dialog instead. This usually consists of an absolutely-positioned DIV and a translucent overlay that covers the whole page.
Alert
并且Confirm
框无法通过脚本关闭。改用模态对话框。这通常由绝对定位的 DIV 和覆盖整个页面的半透明覆盖层组成。