0

i need to check the Internet-connection before calling myurl

$scope.clicked=function(id){
 if($window.navigator.onLine){ 
         $window.open('myurl='+id);
         }else{
            alert('offline');
         }
};
recardo
  • 1
  • 2

1 Answers1

-1
    You can use window.navigator.onLine but no need to write $ before window.
 It works fine if you have only one network connection but it shows online even if you are not connected to internet but with any internal network like loopback adapter too. So best option to check connectivity with internet is html5 Web Socket but itonly works on windows 8 so if you don't have windows 8 then you can use html5 EventSource interface. you can read about it here https://developer.mozilla.org/en-US/docs/Web/API/EventSource
Ankit Sahrawat
  • 1,306
  • 1
  • 11
  • 24
  • Hallo Ankit, I am developing a mobile app with AngularJS, the thing is, I need to check whether internet is available or not, had to work for all browsers – recardo Jan 05 '15 at 12:08