Coder Social home page Coder Social logo

onlinenetwork's Introduction

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("断开网络!")
})

onlinenetwork's People

Contributors

jaywcjlove avatar pc175 avatar

Watchers

theSouthSea avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.