使用html检查互联网连接

使用html检查互联网连接

问题描述:

你好朋友,
我在html5上工作,我想知道如何在html5中使用本地存储并检查Internet连接.
我的问题是,当互联网连接不可用时,我想将数据存储在本地存储中;当互联网连接可用时,我要在互联网连接可用时将数据还原到本地.我想为此使用html5.


hello friends,
i work on html5 i want to know that how to use local storage in html5 and check internet connection.
My problem is that i want to store the data in local storage when internet connectivity not available and when internet connection available the data restore on sever when internet connection available. i want to use html5 for that.


thanks in advance.

HTML5中的本地存储
在这里阅读所有有关它们的信息:
HTML5网络存储 [ HTML5本地存储-完整指南 [ HTML5 localStorage –第一部分 [ HTML5 localStorage –第二部分 [
local storage in html5
Read all about them here:
HTML5 Web Storage[^]
HTML5 Local Storage – Complete Guide[^]
HTML5 localStorage – Part One[^]
HTML5 localStorage – Part Two[^]

It will help you understand on how it can be used.

UPDATE:
how to check the internet connection available or not?
You can determine that the connection is lost by making a request to any URL using XMLHttpRequest. A failed XHR request will confirm no connection.

Though the best one is to use navigator:
Sample:
if(navigator.onLine)
  {
    alert('You are Online');
  }
  else
  {
    alert('You are Offline')
  }


请参阅:使用HTML5和Javascript检查网络状态 [


Refer: Check Network Status using HTML5 and Javascript [^]