Click here to Skip to main content
15,885,365 members
Articles / Programming Languages / Javascript
Tip/Trick

Check connection with WinJS

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
19 Mar 2013LGPL3 9.9K   3  
WinJS connection status

Background 

Checking the state of the network can have very different results: wired connected with or without internet, GSM, an so on. If you only want to know if the user is connected to the internet there isn't any short way, so I made this litle check to have as a snippet of code to our apps.

Using the code

Just copy-paste and use this code: 

JavaScript
var cx = new Windows.Networking.Connectivity.NetworkInformation.getInternetConnectionProfile();

if ((!('getNetworkConnectivityLevel' in cx)) || ((cx.getNetworkConnectivityLevel()) < 3)) {
   alert('Debes estar conectado a internet para ver el contenido. Revisa tu conexión y vuelve a intentar.', 'Atención');
   return false;
} 

Points of interest

For more information about network state check: http://msdn.microsoft.com/en-US/library/windows/apps/windows.networking.connectivity.networkinformation

History

  • 19/03/2013: First version.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Student Opentags
Argentina Argentina
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --