我想能够在一定的时间或特定的事件(即onkeypress)之后自动关闭一个警报框。从我的研究来看,内置的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关闭警报框
发布评论