user3668991
user3668991

Reputation: 11

phonegap 3.4: bug with event online / offline

In phonegap when the event online product I trigger a reload of data but the problem is that the online or offline event fires two times in succession: it is creating a bug!

Here is my code:

document.addEventListener ("deviceready" onDeviceReady, false);
document.addEventListener ("online", onOnline, false);
document.addEventListener ("offline", onOffline, false);

Could you help me

thank you

Upvotes: 1

Views: 447

Answers (2)

benka
benka

Reputation: 4742

I would only add online and offline event listeners after the device is ready:

document.addEventListener ("deviceready" onDeviceReady, false);

function onDeviceReady() {
    document.addEventListener ("online", onOnline, false);
    document.addEventListener ("offline", onOffline, false);
}


function onOnline(){
}

function onOffline(){
}

Upvotes: 1

byJeevan
byJeevan

Reputation: 3838

Try by add plugin in this way:

cordova plugin add org.apache.cordova.network-information

For further details refer this link.

Upvotes: 0

Related Questions