0

嗨,如果用户没有互联网连接,我目前正在处理重定向

警告连接的示例代码

function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.NONE]     = 'No network connection';

    alert('Connection type: ' + states[networkState]);
}

所以我把它改成

function InternetOK(){
        var networkState =navigator.connection.type
        var states = {};
        if (state == "NONE" ){
           window.location = "offline.html";
            }
        }

此代码在 index.html 中

<html>
<body>
<div class="iamstupid">
  <a href="news.html" onClick="InternetOK();">News</a>
.
.
.

出了点问题。

4

1 回答 1

0

解决了

函数 checkConnection(){ var networkState = navigator.connection.type;

   if (networkState == Connection.NONE ){
   window.location = "offline.html";
   } 

}

于 2013-01-18T12:01:23.773 回答