https://github.com/jaywcjlove/onlinenetwork
js判断是否断网了
https://github.com/jaywcjlove/onlinenetwork
Last synced: 2 months ago
JSON representation
js判断是否断网了
- Host: GitHub
- URL: https://github.com/jaywcjlove/onlinenetwork
- Owner: jaywcjlove
- Created: 2015-02-15T13:04:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-02-01T20:39:19.000Z (over 1 year ago)
- Last Synced: 2024-10-29T11:13:32.261Z (8 months ago)
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 98
- Watchers: 5
- Forks: 38
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# js判断是否断网了
[](https://github.com/jaywcjlove/onlinenetwork/issues) [](https://github.com/jaywcjlove/onlinenetwork/network) [](https://github.com/jaywcjlove/onlinenetwork/stargazers)
此方法是通过 `online` 和 `offline` 事件来侦听是否断网,但是这个在 `IE ` 和 `Firefox` 中,并非断网了就是真的断网了。(如火狐中在选择 `菜单>>文件>>脱机工作`才会触发 `online` 和 `offline` 事件)
总之在`IE`和`Firefox`中一般情况下不能触发这俩事件,只有在选择脱机状态下才能触发此事件。
## 下载
```
$ bower info onlinenetwork
```## 引用 `online.js`
```html
```
## 设置轮询时间和地址
> time: 时间不设置默认2000
> url:不设置默认所有浏览器用 `online` 和 `offline`事件```js
var net = onlinenetwork({
"time":1000,
"url":"http://*******.com/ping.php"
})
```## 连上网络执行
```js
net.onLineHandler(function(){
console.log("连上了!")
})
```## 断开网络执行
```js
net.offLineHandler(function(){
console.log("断开网络!")
})
```