1

我们正在使用 HTML5 离线缓存。我们有轮询代码来检查用户是否连接到服务器/网络。在线检测是通过调用网络部分下的appcache文件中提到的一个测试jsp页面来完成的。此检查通过将响应状态返回为 0 在 Chrome
中起作用。但在 Firefox 中不起作用。Firefox 显示后备页面而不是提供离线状态(代码 0)。在这种情况下,响应状态码仍然是 200。
我的应用缓存是:

CACHE MANIFEST
index.html

NETWORK:
TestIsOnline.jsp

FALLBACK:
/ fallback.html

检查状态的代码是:

$http({method: 'GET', url: 'TestIsOnline.jsp', cache: false}).success(function(data, status) {
   console.log("user is online: status:"+status);
}).error(function(data, status) {
   console.log("user is offline: status:"+status);
});

并调用测试页面“TestIsOnline.jsp”包含:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="cache-control" content="max-age=0" />
  <meta http-equiv="cache-control" content="no-cache" />
  <meta http-equiv="expires" content="0" />
  <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
  <meta http-equiv="pragma" content="no-cache" />
  <title>To test online status</title>
</head>
<body>
  test page
</body>
</html>

当我断开服务器时,在 chrome 中我得到输出为“用户离线:状态:0”。
在 Firefox 中,我仍然收到“用户在线:状态:200”。
如何在这里检测离线模式?

4

0 回答 0