我需要在调用myurl之前检查Internet连接
$scope.clicked=function(id){
if($window.navigator.onLine){
$window.open('myurl='+id);
}else{
alert('offline');
}
};
答案 0 :(得分:-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