Javascript关闭警告框 [英] Javascript close alert box

查看:40
本文介绍了Javascript关闭警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在一定时间后或在特定事件(即 onkeypress)后使用 Javascript 自动关闭警报框.根据我的研究,使用内置的 alert() 函数似乎不可能.有没有办法覆盖它并控制它打开的对话框?

I want to be able to close an alert box automatically using Javascript after a certain amount of time or on a specific event (i.e. onkeypress). From my research, it doesn't look like that's possible with the built-in alert() function. Is there a way to override it and have control over the dialog box that it opens?

另外,我不想要一个将隐藏的 div 显示为警报的覆盖.我需要一个实际的对话框.

Also, I don't want an override that shows a hidden div as the alert. I need an actual dialog box.

推荐答案

如前所述,你真的不能这样做.您可以使用 UI 框架在窗口内创建一个模态对话框,或者您可以创建一个弹出窗口,其中包含一个在超时后自动关闭的脚本……每个都有一个消极方面.如果窗口被最小化,浏览器内的模态窗口将不会创建任何通知,并且程序化(基于定时器的)弹出窗口很可能被现代浏览器和弹出窗口阻止程序阻止.

As mentioned previously you really can't do this. You can do a modal dialog inside the window using a UI framework, or you can have a popup window, with a script that auto-closes after a timeout... each has a negative aspect. The modal window inside the browser won't create any notification if the window is minimized, and a programmatic (timer based) popup is likely to be blocked by modern browsers, and popup blockers.

这篇关于Javascript关闭警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆