Skip to content

Instantly share code, notes, and snippets.

@scottjehl
Created April 28, 2011 19:16
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save scottjehl/947084 to your computer and use it in GitHub Desktop.
Save scottjehl/947084 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