Click here to Skip to main content
Click here to Skip to main content

Check connection with WinJS

By , 19 Mar 2013
 

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: 

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)

About the Author

Mariano MountainMan Ureta
Argentina Argentina
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130513.1 | Last Updated 19 Mar 2013
Article Copyright 2013 by Mariano MountainMan Ureta
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid