Page 1 of 1

Issue with getting connection state.

Posted: Sat Mar 17, 2012 8:25 pm
by RyanShay

I have a splash page, which only has a single image on it.

On load, I have the following custom JS:

alert('test');
//var type = navigator.network.connection.type;
//alert(type);

The "test" alert works, if I comment out the two lines for the type.
If I attempt to get the connection type by uncommenting the last two lines, the page just hangs on a white screen and nothing happens.

I have only tested this in the Tiggzi Tester for iPhone as I cannot get the one for Android to work. (posted a separate topic for that).

I'm happy to provide any additional info that is needed.

Thanks!


Issue with getting connection state.

Posted: Sat Mar 17, 2012 9:07 pm
by maxkatz

Hmm...I just tried this on Android and it worked.


Issue with getting connection state.

Posted: Sat Mar 17, 2012 9:18 pm
by RyanShay

That's odd, not working on my Droid either. Android 2.2. I just get the white page.
I'm using the blank app I added to test the other Android issue, the only thing on the project is the single initial screen with a Load event to run the custom js:

alert(navigator.network.connection.type);

Does this need to be inside a function, or be watching the onDeviceReady before trying to alert?


Issue with getting connection state.

Posted: Sat Mar 17, 2012 9:33 pm
by RyanShay

Sorry to waste your time Max. Answered my own question. The following does work:

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

function onDeviceReady(){
alert(navigator.network.connection.type);
}


Issue with getting connection state.

Posted: Sat Mar 17, 2012 9:58 pm
by maxkatz

Onload is too early, PhoneGap hasn't loaded yet. If you look under Events tab, there is ondeviceready event you can use.