在 Javascript 中以编程方式关闭 alert()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23485086/
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
Programmatically close alert() in Javascript
提问by forwardslashend
I'm trying to trigger an alert close once an event happens. Currently I get a popup when the internet cuts out (I want that). But once the connection is reestablished, I want the popup to automatically go away - not having to hit exit or OK.
我试图在事件发生后触发警报关闭。目前,当互联网中断时,我会弹出一个窗口(我想要那个)。但是一旦重新建立连接,我希望弹出窗口自动消失 - 不必点击退出或确定。
I have this code:
我有这个代码:
setInterval(function(){
if(navigator.onLine){
( ".selector" ).popup( "close" );
}else{
window.alert("It seems you have lost connection to the internet.
Please reconnect before continuing.");
}},2000);
Thanks
谢谢
采纳答案by marcineck
As far as I know you cannot close the javascript's alert();
by code. You can try to use alternative notification method like modal window or something (so then if user is back online you can simply use jQuery function to hide/remove the modal box).
据我所知,您无法alert();
通过代码关闭 javascript 。您可以尝试使用其他通知方法,例如模态窗口或其他方式(这样,如果用户重新在线,您可以简单地使用 jQuery 函数来隐藏/删除模态框)。
回答by Lasitha Benaragama
According to my knowledge Java Script Alert box cant be change or close programmatically. So you can use Jquery UI Dialog boxor bootstrap modelor something else.
据我所知,Java Script Alert 框无法以编程方式更改或关闭。所以你可以使用Jquery UI 对话框或引导模型或其他东西。