使用html检查互联网连接 [英] check internet connection using html

查看:128
本文介绍了使用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 [^]


这篇关于使用html检查互联网连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆