没有互联网连接时的警报框

没有互联网连接时的警报框

本文介绍了没有互联网连接时的警报框 - Phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在设备上没有互联网连接时弹出一个弹出窗口。

I'm trying to get a pop-up to, well, pop up when there is no internet connection on the device.

我得到了工作,但现在我想要仅当结果为无网络连接时才显示警报 。

I got the following example working, but now I want the alert only to show when the result is "No network connection".

我尝试过:

if (states[Connection.NONE]){
       alert('Geen internet :(');
       };


$ b b

但是,只是使警报框弹出,无论是否有连接。
谁可以帮助我?)

But that just makes the alert-box pop up, no matter if there is a connection or not.Who can help me? :)

推荐答案

老问题,但这里是我怎么做 - 你可以使用事件来检测设备是在线还是离线。这对于这种情况是理想的,因为一旦设备离线就会出现弹出窗口:

Old-ish question, but here's how I'd do it - You can use events to detect if the device is online or offline. This is ideal for this situation as the pop-up will appear as soon as the device goes offline:

document.addEventListener(offline function(){alert(You're offline)},false);

重新连接互联网?:

document.addEventListener(online,function(){alert(You're online false);

查看活动文档:

UPDATE:

这些活动已移至

这篇关于没有互联网连接时的警报框 - Phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 23:55