Skip to content

jaywcjlove/onlinenetwork

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

js判断是否断网了

GitHub issues GitHub forks GitHub stars

此方法是通过 onlineoffline 事件来侦听是否断网,但是这个在 IE Firefox 中,并非断网了就是真的断网了。(如火狐中在选择 菜单>>文件>>脱机工作才会触发 onlineoffline 事件)

总之在IEFirefox中一般情况下不能触发这俩事件,只有在选择脱机状态下才能触发此事件。

下载

$ bower info onlinenetwork

引用 online.js

<script type="text/javascript" src="online.js"></script>

设置轮询时间和地址

time: 时间不设置默认2000
url:不设置默认所有浏览器用 onlineoffline事件

var net = onlinenetwork({
    "time":1000,
    "url":"http://*******.com/ping.php"
})

连上网络执行

net.onLineHandler(function(){
    console.log("连上了!")
})

断开网络执行

net.offLineHandler(function(){
    console.log("断开网络!")
})