<html>
<head>
<title>Cordova Offline Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.9.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Call onDeviceReady when Cordova is loaded.
//
// At this point, the document has loaded but cordova-1.9.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function Network(){
if(navigator.onLine)
{
alert('You are Online');
}
else
{
alert('You are Offline')
}
}
</script>
</head>
<body >
<input type="button" value="Check Network" onclick="Network()" />
</body>
</html>
html 코드를 사용하여 네트워크 연결을 확인하려고합니다. 내 로컬 컴퓨터의 crome에서이 코드를 실행하지만 안드로이드에서 작동하지 않는 이유는 작동합니다.phonegap을 사용하여 html 5 코드가 안드로이드에서 작동하지 않습니다.
위의 코드 문제는 오프라인 상태 인 장치와 navigator.onLine 속성을 지원하지 않는 장치의 차이점을 알 수 없다는 것입니다. 내 생각 엔 안드로이드 브라우저가 지원하지 않을 것입니다. if 문의 시작 부분에 if (navigator.onLine === undefined)를 추가하여 지원 여부를 확인하십시오. –
이 경우 왜 온라인 상태 일 때 navigator.onLine = true가됩니다. – vishalg
navigator.onLine은 브라우저의 온라인 상태를 반환하므로 IE 및 Firefox와 같이 상태를 '오프라인으로 작업'으로 변경하는 기능을 제공하는 브라우저가 거의 없습니다. Chrome은 사용 가능한 네트워크에 연결되어있는 한 언제나 onLine을 제공합니다. – dhaval