Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Check connection with WinJS

5.00/5 (1 vote)
19 Mar 2013LGPL3 10K  
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)