All Projects → jaywcjlove → Onlinenetwork

jaywcjlove / Onlinenetwork

js判断是否断网了

Programming Languages

javascript
184084 projects - #8 most used programming language

js判断是否断网了

GitHub issues GitHub forks GitHub stars

此方法是通过 onlineoffline 事件来侦听是否断网,但是这个在 IEFirefox 中,并非断网了就是真的断网了。(如火狐中在选择 菜单>>文件>>脱机工作才会触发 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("断开网络!")
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].