Skip to content

Instantly share code, notes, and snippets.

@lxneng
Forked from scottjehl/hasInternets.js
Created July 12, 2011 03:35
Show Gist options
  • Save lxneng/1077343 to your computer and use it in GitHub Desktop.
Save lxneng/1077343 to your computer and use it in GitHub Desktop.
quick check for online status with jQuery
//quick online/offline check
function hasInternets() {
var s = $.ajax({
type: "HEAD",
url: window.location.href.split("?")[0] + "?" + Math.random(),
async: false
}).status;
//thx http://www.louisremi.com/2011/04/22/navigator-online-alternative-serverreachable/
return s >= 200 && s < 300 || s === 304;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment