jaywcjlove / Onlinenetwork
js判断是否断网了
Stars: ✭ 75
Programming Languages
javascript
184084 projects - #8 most used programming language
js判断是否断网了
此方法是通过 online
和 offline
事件来侦听是否断网,但是这个在 IE
和 Firefox
中,并非断网了就是真的断网了。(如火狐中在选择 菜单>>文件>>脱机工作
才会触发 online
和 offline
事件)
总之在IE
和Firefox
中一般情况下不能触发这俩事件,只有在选择脱机状态下才能触发此事件。
下载
$ bower info onlinenetwork
online.js
引用 <script type="text/javascript" src="online.js"></script>
设置轮询时间和地址
time: 时间不设置默认2000
url:不设置默认所有浏览器用online
和offline
事件
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].