以编程方式关闭Javascript中的alert()

时间:2014-05-06 02:36:34

标签: javascript alert

我正试图在事件发生时触发警报关闭。目前,当互联网被淘汰时,我会得到一个弹出窗口(我希望如此)。但是一旦连接重新建立,我希望弹出窗口自动消失 - 不必点击退出或OK。

我有这段代码:

 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);

由于

2 个答案:

答案 0 :(得分:5)

据我所知,你不能通过代码关闭javascript的alert();。您可以尝试使用替代通知方法,如模态窗口或其他东西(因此,如果用户重新上线,您只需使用jQuery函数隐藏/删除模式框)。

答案 1 :(得分:1)

据我所知,Java Script Alert框无法以编程方式更改或关闭。因此,您可以使用Jquery UI Dialog boxbootstrap model或其他内容。