RyanShay
Posts: 0
Joined: Mon Mar 12, 2012 2:29 am

Issue with getting connection state.

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Issue with getting connection state.

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

RyanShay
Posts: 0
Joined: Mon Mar 12, 2012 2:29 am

Issue with getting connection state.

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?

RyanShay
Posts: 0
Joined: Mon Mar 12, 2012 2:29 am

Issue with getting connection state.

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Issue with getting connection state.

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

Return to “Issues”